From b18f916ab3a4f433720055c505753de882af04c2 Mon Sep 17 00:00:00 2001 From: Diana Chukhrai Date: Tue, 27 Jan 2026 14:41:25 +0100 Subject: [PATCH] ex1/2/3/4 --- task-1/book.js | 8 ++++++- task-2/parse-date.js | 38 ++++++++++++++++++++++++++++++- task-3/date.js | 33 +++++++++++++++++++++++++++ task-4/cleanup.js | 54 +++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 task-3/date.js diff --git a/task-1/book.js b/task-1/book.js index 8b49ecc..6693b81 100644 --- a/task-1/book.js +++ b/task-1/book.js @@ -1,3 +1,9 @@ +const bookName = "The fundamentals of JavaScript"; + function isBookApplicable(searchString) { - // Your code here + const cleanSearch = searchString.trim().toLowerCase(); + const cleanBook = bookName.toLowerCase(); + + const containWord = cleanBook.includes(cleanSearch); + return containWord; } diff --git a/task-2/parse-date.js b/task-2/parse-date.js index 877a3aa..670314c 100644 --- a/task-2/parse-date.js +++ b/task-2/parse-date.js @@ -1 +1,37 @@ -// Your code here +function parseDateString(dateString) { + const format = dateString.slice(0, 3); // "MDY" або "DMY" + const datePart = dateString.slice(4); // "10-21-1983" + + const first = Number(datePart.slice(0, 2)); + const second = Number(datePart.slice(3, 5)); + const year = Number(datePart.slice(6, 10)); + + let day; + let month; + + if (format === "MDY") { + month = first; + day = second; + } else if (format === "DMY") { + day = first; + month = second; + } else { + console.log("Wrong format. Use MDY or DMY"); + return null; + } + + return { day, month, year }; +} + + +console.log(parseDateString("MDY 10-21-1983")); +// Output: { day: 21, month: 10, year: 1983 } + +console.log(parseDateString("DMY 21-10-1983")); +// Output: { day: 21, month: 10, year: 1983 } + +console.log(parseDateString("MDY 03-15-2024")); +// Output: { day: 15, month: 3, year: 2024 } + +console.log(parseDateString("DMY 15-03-2024")); +// Output: { day: 15, month: 3, year: 2024 } \ No newline at end of file diff --git a/task-3/date.js b/task-3/date.js new file mode 100644 index 0000000..8ee552a --- /dev/null +++ b/task-3/date.js @@ -0,0 +1,33 @@ + + +// convertHoursToMinutes, +// convertMinutesToHours, +// convertDaysToHours, +// convertHoursToDays, +// convertMinutesToSeconds, +// convertSecondsToMinutes + + +export function convertHoursToMinutes(hours){ + return hours * 60; +} + +export function convertMinutesToHours(minutes){ + return minutes / 60; +} + +export function convertDaysToHours(days) { + return days * 24; +} + +export function convertHoursToDays(hours) { + return hours / 24; +} + +export function convertMinutesToSeconds(minutes) { + return minutes * 60; +} + +export function convertSecondsToMinutes(seconds) { + return seconds / 60; +} diff --git a/task-4/cleanup.js b/task-4/cleanup.js index 207523a..3f44777 100644 --- a/task-4/cleanup.js +++ b/task-4/cleanup.js @@ -77,4 +77,56 @@ console.log("Wind chill in " + cityName2 + ": " + windChill2.toFixed(2) + "°C") // Wind chill calculation for City 3 let windSpeed3 = 25; let windChill3 = 13.12 + 0.6215 * tempCelsius3 - 11.37 * Math.pow(windSpeed3, 0.16) + 0.3965 * tempCelsius3 * Math.pow(windSpeed3, 0.16); -console.log("Wind chill in " + cityName3 + ": " + windChill3.toFixed(2) + "°C"); \ No newline at end of file +console.log("Wind chill in " + cityName3 + ": " + windChill3.toFixed(2) + "°C"); + + + + +//DRY + +function cityName(name) { + return `Weather Report for ${name}`; +} + +function getStatusCelsius(celsius) { + if (celsius < 0) return "Status: Freezing"; + if (celsius < 10) return "Status: Cold"; + if (celsius < 20) return "Status: Mild"; + if (celsius < 30) return "Status: Warm"; + return "Status: Hot"; +} + +function getStatusFahrenheit(celsius) { + return (celsius * 9 / 5) + 32; +} + +function getStatusKelvin(celsius) { + return celsius + 273.15; +} + +function calculateWindChill(tempCelsius, windSpeed) { + const windSpeedPower = Math.pow(windSpeed, 0.16); + + const windChill = + 13.12 + + 0.6215 * tempCelsius - + 11.37 * windSpeedPower + + 0.3965 * tempCelsius * windSpeedPower; + + return windChill; +} + +function printWindChill(city, tempCelsius, windSpeed) { + const windChill = calculateWindChill(tempCelsius, windSpeed); + console.log(`Wind chill in ${city}: ${windChill.toFixed(2)}°C`); +} + +function printWeatherReport(cityNameValue, celsius, windSpeed) { + console.log(cityName(cityNameValue)); + console.log(`Temperature: ${celsius}°C`); + console.log(`Temperature: ${getStatusFahrenheit(celsius)}°F`); + console.log(`Temperature: ${getStatusKelvin(celsius)}K`); + console.log(getStatusCelsius(celsius)); + printWindChill(cityNameValue, celsius, windSpeed); + console.log("---"); +} \ No newline at end of file