From 4bf431a8a524f14efc139bf1b25cbc384404f607 Mon Sep 17 00:00:00 2001 From: Yana Pechenenko Date: Tue, 27 Jan 2026 12:02:03 +0100 Subject: [PATCH 1/5] Add function for searching a string --- task-1/book.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/task-1/book.js b/task-1/book.js index 8b49ecc..636bee2 100644 --- a/task-1/book.js +++ b/task-1/book.js @@ -1,3 +1,17 @@ function isBookApplicable(searchString) { - // Your code here + const bookName = "The fundamentals of JavaScript".toLowerCase(); + const pureString = searchString.trim().toLowerCase(); + + if(!pureString) return false; + + return bookName.includes(pureString); } + +// console.log(isBookApplicable("javascript")); +// console.log(isBookApplicable("j2vascript ")); +// console.log(isBookApplicable("python")); +// console.log(isBookApplicable("JavaScript")); +// console.log(isBookApplicable("JAVASCRIPT")); +// console.log(isBookApplicable("fundamentals")); +// console.log(isBookApplicable("fundamentals of1 JavaScript")); +// console.log(isBookApplicable(" ")); \ No newline at end of file From fc13393ab2a52608212368c270626828e2fd7401 Mon Sep 17 00:00:00 2001 From: Yana Pechenenko Date: Tue, 27 Jan 2026 12:03:03 +0100 Subject: [PATCH 2/5] Add function for parse date --- task-2/parse-date.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/task-2/parse-date.js b/task-2/parse-date.js index 877a3aa..6c3d44b 100644 --- a/task-2/parse-date.js +++ b/task-2/parse-date.js @@ -1 +1,29 @@ -// Your code here +function parseDateString(dateString) { + const indexOfSpace = dateString.indexOf(" "); + const format = dateString.substring(0, indexOfSpace); + const date = dateString.substring(indexOfSpace); + + const firstDash = date.indexOf("-"); + const lastDash = date.lastIndexOf("-"); + + const first = Number(date.substring(0, firstDash)); + const second = Number(date.substring(firstDash + 1, lastDash)); + const third = Number(date.substring(lastDash + 1)); + + if(isNaN(first) || isNaN(second) || isNaN(third)){ + return 'Invalid date!'; + } + + if(format === "MDY"){ + return {day: second, month: first, year: third } + } else if(format === "DMY"){ + return {day: first, month: second, year: third } + } else {return 'Invalid format!'} + + } + +// console.log(parseDateString("MDY 10-21-1983")); +// console.log(parseDateString("DMY 21-10-1983")); +// console.log(parseDateString("DM 21-10-1983")); +// console.log(parseDateString(" ")); +// console.log(parseDateString("DMY 21fsdfksdv;jf-10-1983")); \ No newline at end of file From 2aedf41d7aeff01e351071a1dc04627c021dbd43 Mon Sep 17 00:00:00 2001 From: Yana Pechenenko Date: Tue, 27 Jan 2026 12:04:57 +0100 Subject: [PATCH 3/5] Add date.js file and functions for convert time --- task-3/date.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 task-3/date.js diff --git a/task-3/date.js b/task-3/date.js new file mode 100644 index 0000000..54b122b --- /dev/null +++ b/task-3/date.js @@ -0,0 +1,11 @@ +export const convertHoursToMinutes = hours => hours * 60; + +export const convertMinutesToHours = minutes => minutes / 60; + +export const convertDaysToHours = days => days * 24; + +export const convertHoursToDays = hours => hours / 24; + +export const convertMinutesToSeconds = minutes => minutes * 60; + +export const convertSecondsToMinutes = seconds => seconds / 60; \ No newline at end of file From 90ae191438d0ac25d5e728cb0df69e458544a2a3 Mon Sep 17 00:00:00 2001 From: Yana Pechenenko Date: Tue, 27 Jan 2026 12:10:32 +0100 Subject: [PATCH 4/5] Refactor code, split it into 6 separate functions, add two new cities for testing --- task-4/cleanup.js | 125 ++++++++++++++++++++-------------------------- 1 file changed, 53 insertions(+), 72 deletions(-) diff --git a/task-4/cleanup.js b/task-4/cleanup.js index 207523a..a66ae0c 100644 --- a/task-4/cleanup.js +++ b/task-4/cleanup.js @@ -1,80 +1,61 @@ -// Temperature conversion and weather report for City 1 -let cityName1 = "Amsterdam"; -let tempCelsius1 = 22; -let tempFahrenheit1 = (tempCelsius1 * 9 / 5) + 32; -let tempKelvin1 = tempCelsius1 + 273.15; -console.log("Weather Report for " + cityName1); -console.log("Temperature: " + tempCelsius1 + "°C"); -console.log("Temperature: " + tempFahrenheit1 + "°F"); -console.log("Temperature: " + tempKelvin1 + "K"); -if (tempCelsius1 < 0) { - console.log("Status: Freezing"); -} else if (tempCelsius1 >= 0 && tempCelsius1 < 10) { - console.log("Status: Cold"); -} else if (tempCelsius1 >= 10 && tempCelsius1 < 20) { - console.log("Status: Mild"); -} else if (tempCelsius1 >= 20 && tempCelsius1 < 30) { - console.log("Status: Warm"); -} else { - console.log("Status: Hot"); +function fullWeatherReport(city, celsius, speed){ + const part_1 = weatherReport(city, celsius); + const part_2 = windChillCalculation(city, celsius, speed); + + return `${part_1}\n${part_2}` } -console.log("---"); -// Temperature conversion and weather report for City 2 -let cityName2 = "Berlin"; -let tempCelsius2 = 15; -let tempFahrenheit2 = (tempCelsius2 * 9 / 5) + 32; -let tempKelvin2 = tempCelsius2 + 273.15; -console.log("Weather Report for " + cityName2); -console.log("Temperature: " + tempCelsius2 + "°C"); -console.log("Temperature: " + tempFahrenheit2 + "°F"); -console.log("Temperature: " + tempKelvin2 + "K"); -if (tempCelsius2 < 0) { - console.log("Status: Freezing"); -} else if (tempCelsius2 >= 0 && tempCelsius2 < 10) { - console.log("Status: Cold"); -} else if (tempCelsius2 >= 10 && tempCelsius2 < 20) { - console.log("Status: Mild"); -} else if (tempCelsius2 >= 20 && tempCelsius2 < 30) { - console.log("Status: Warm"); -} else { - console.log("Status: Hot"); +function weatherReport(city, celsius){ + const fahrenheit = toFahrenheit(celsius); + const kelvin = toKelvin(celsius); + const status = weatherStatus(celsius); + + return `Weather Report for ${city} \nTemperature: ${celsius}°C \nTemperature: ${fahrenheit}°F \nTemperature: ${kelvin}K \n${status} \n---`} + +function toFahrenheit(celsius){ + return (celsius * 9 / 5) + 32; +} + +function toKelvin(celsius){ + return celsius + 273.15; +} + +function weatherStatus(celsius){ + if (celsius < 0) { + return "Status: Freezing"; + } else if (celsius >= 0 && celsius < 10) { + return "Status: Cold"; + } else if (celsius >= 10 && celsius < 20) { + return "Status: Mild"; + } else if (celsius >= 20 && celsius < 30) { + return "Status: Warm"; + } else { + return "Status: Hot"; + } } -console.log("---"); -// Temperature conversion and weather report for City 3 -let cityName3 = "Copenhagen"; -let tempCelsius3 = -5; -let tempFahrenheit3 = (tempCelsius3 * 9 / 5) + 32; -let tempKelvin3 = tempCelsius3 + 273.15; -console.log("Weather Report for " + cityName3); -console.log("Temperature: " + tempCelsius3 + "°C"); -console.log("Temperature: " + tempFahrenheit3 + "°F"); -console.log("Temperature: " + tempKelvin3 + "K"); -if (tempCelsius3 < 0) { - console.log("Status: Freezing"); -} else if (tempCelsius3 >= 0 && tempCelsius3 < 10) { - console.log("Status: Cold"); -} else if (tempCelsius3 >= 10 && tempCelsius3 < 20) { - console.log("Status: Mild"); -} else if (tempCelsius3 >= 20 && tempCelsius3 < 30) { - console.log("Status: Warm"); -} else { - console.log("Status: Hot"); +function windChillCalculation(city, celsius, speed){ + const windChill = (13.12 + 0.6215 * celsius - 11.37 * Math.pow(speed, 0.16) + 0.3965 * celsius * Math.pow(speed, 0.16)).toFixed(2); + + return `Wind chill in ${city}: ${windChill}°C`; } -console.log("---"); -// Wind chill calculation for City 1 -let windSpeed1 = 15; -let windChill1 = 13.12 + 0.6215 * tempCelsius1 - 11.37 * Math.pow(windSpeed1, 0.16) + 0.3965 * tempCelsius1 * Math.pow(windSpeed1, 0.16); -console.log("Wind chill in " + cityName1 + ": " + windChill1.toFixed(2) + "°C"); -// Wind chill calculation for City 2 -let windSpeed2 = 20; -let windChill2 = 13.12 + 0.6215 * tempCelsius2 - 11.37 * Math.pow(windSpeed2, 0.16) + 0.3965 * tempCelsius2 * Math.pow(windSpeed2, 0.16); -console.log("Wind chill in " + cityName2 + ": " + windChill2.toFixed(2) + "°C"); +// console.log(weatherReport("Amsterdam", 22)); +// console.log(windChillCalculation("Amsterdam", 22, 15)); +// console.log(weatherReport("Berlin", 15)); +// console.log(windChillCalculation("Berlin", 15, 20)); +// console.log(weatherReport("Copenhagen", -5)); +// console.log(windChillCalculation("Copenhagen", -5, 25)); + +// console.log(fullWeatherReport("Amsterdam", 22, 15)); +// console.log(fullWeatherReport("Berlin", 15, 20)); +// console.log(fullWeatherReport("Copenhagen", -5, 25)); + +// console.log(weatherReport("Odesa", -8)); +// console.log(windChillCalculation("Odesa", -8, 13)); +// console.log(weatherReport("Antwerpen", 3)); +// console.log(windChillCalculation("Antwerpen", 3, 36)); -// 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(fullWeatherReport("Odesa", -8, 13)); +// console.log(fullWeatherReport("Antwerpen", 3, 36)); \ No newline at end of file From e4c658032c3884477e619c3eb19c8f44619824aa Mon Sep 17 00:00:00 2001 From: Yana Pechenenko Date: Wed, 11 Feb 2026 22:09:09 +0100 Subject: [PATCH 5/5] use split(-) in task-2 and change some variables name for more descriptive in task-2 & task-4 --- task-2/parse-date.js | 34 +++++++++++++---------------- task-4/cleanup.js | 51 ++++++++++++++++++++++++-------------------- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/task-2/parse-date.js b/task-2/parse-date.js index 6c3d44b..4b5f10b 100644 --- a/task-2/parse-date.js +++ b/task-2/parse-date.js @@ -1,29 +1,25 @@ function parseDateString(dateString) { - const indexOfSpace = dateString.indexOf(" "); - const format = dateString.substring(0, indexOfSpace); - const date = dateString.substring(indexOfSpace); + const indexOfSpace = dateString.indexOf(" "); + const format = dateString.substring(0, indexOfSpace); + const date = dateString.substring(indexOfSpace); - const firstDash = date.indexOf("-"); - const lastDash = date.lastIndexOf("-"); + const [day, month, year] = date.split("-"); - const first = Number(date.substring(0, firstDash)); - const second = Number(date.substring(firstDash + 1, lastDash)); - const third = Number(date.substring(lastDash + 1)); - - if(isNaN(first) || isNaN(second) || isNaN(third)){ - return 'Invalid date!'; - } - - if(format === "MDY"){ - return {day: second, month: first, year: third } - } else if(format === "DMY"){ - return {day: first, month: second, year: third } - } else {return 'Invalid format!'} + if (isNaN(day) || isNaN(month) || isNaN(year)) { + return "Invalid date!"; + } + if (format === "DMY") { + return { day, month, year }; + } else if (format === "MDY") { + return { day: month, month: day, year }; + } else { + return "Invalid format!"; } +} // console.log(parseDateString("MDY 10-21-1983")); // console.log(parseDateString("DMY 21-10-1983")); // console.log(parseDateString("DM 21-10-1983")); // console.log(parseDateString(" ")); -// console.log(parseDateString("DMY 21fsdfksdv;jf-10-1983")); \ No newline at end of file +// console.log(parseDateString("DMY 21fsdfksdv;jf-10-1983")); diff --git a/task-4/cleanup.js b/task-4/cleanup.js index a66ae0c..51590ea 100644 --- a/task-4/cleanup.js +++ b/task-4/cleanup.js @@ -1,46 +1,51 @@ -function fullWeatherReport(city, celsius, speed){ - const part_1 = weatherReport(city, celsius); - const part_2 = windChillCalculation(city, celsius, speed); +function fullWeatherReport(city, celsius, speed) { + const reportWeather = weatherReport(city, celsius); + const reportWind = windChillCalculation(city, celsius, speed); - return `${part_1}\n${part_2}` + return `${reportWeather}\n${reportWind}`; } -function weatherReport(city, celsius){ +function weatherReport(city, celsius) { const fahrenheit = toFahrenheit(celsius); const kelvin = toKelvin(celsius); const status = weatherStatus(celsius); - - return `Weather Report for ${city} \nTemperature: ${celsius}°C \nTemperature: ${fahrenheit}°F \nTemperature: ${kelvin}K \n${status} \n---`} -function toFahrenheit(celsius){ - return (celsius * 9 / 5) + 32; -} + return `Weather Report for ${city} \nTemperature: ${celsius}°C \nTemperature: ${fahrenheit}°F \nTemperature: ${kelvin}K \n${status} \n---`; +} + +function toFahrenheit(celsius) { + return (celsius * 9) / 5 + 32; +} -function toKelvin(celsius){ +function toKelvin(celsius) { return celsius + 273.15; -} +} -function weatherStatus(celsius){ +function weatherStatus(celsius) { if (celsius < 0) { - return "Status: Freezing"; + return "Status: Freezing"; } else if (celsius >= 0 && celsius < 10) { - return "Status: Cold"; + return "Status: Cold"; } else if (celsius >= 10 && celsius < 20) { - return "Status: Mild"; + return "Status: Mild"; } else if (celsius >= 20 && celsius < 30) { - return "Status: Warm"; + return "Status: Warm"; } else { - return "Status: Hot"; + return "Status: Hot"; } } -function windChillCalculation(city, celsius, speed){ - const windChill = (13.12 + 0.6215 * celsius - 11.37 * Math.pow(speed, 0.16) + 0.3965 * celsius * Math.pow(speed, 0.16)).toFixed(2); +function windChillCalculation(city, celsius, speed) { + const windChill = ( + 13.12 + + 0.6215 * celsius - + 11.37 * Math.pow(speed, 0.16) + + 0.3965 * celsius * Math.pow(speed, 0.16) + ).toFixed(2); - return `Wind chill in ${city}: ${windChill}°C`; + return `Wind chill in ${city}: ${windChill}°C`; } - // console.log(weatherReport("Amsterdam", 22)); // console.log(windChillCalculation("Amsterdam", 22, 15)); // console.log(weatherReport("Berlin", 15)); @@ -58,4 +63,4 @@ function windChillCalculation(city, celsius, speed){ // console.log(windChillCalculation("Antwerpen", 3, 36)); // console.log(fullWeatherReport("Odesa", -8, 13)); -// console.log(fullWeatherReport("Antwerpen", 3, 36)); \ No newline at end of file +// console.log(fullWeatherReport("Antwerpen", 3, 36));