From 340653e4093e1feb9a6929b4c617a3c158411dd3 Mon Sep 17 00:00:00 2001 From: mohammedalfakih-dev Date: Thu, 29 Jan 2026 01:23:25 +0100 Subject: [PATCH 1/4] date library added --- task-3/date.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 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..1bc5ee3 --- /dev/null +++ b/task-3/date.js @@ -0,0 +1,24 @@ +// Date library module +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; +} \ No newline at end of file From b65cf5a3566c9310d91d9147c1b548d90f5a1efa Mon Sep 17 00:00:00 2001 From: mohammedalfakih-dev Date: Thu, 29 Jan 2026 01:39:38 +0100 Subject: [PATCH 2/4] Adding book search funtion --- task-1/book.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/task-1/book.js b/task-1/book.js index 8b49ecc..57bd448 100644 --- a/task-1/book.js +++ b/task-1/book.js @@ -1,3 +1,26 @@ function isBookApplicable(searchString) { - // Your code here + const bookTitle = "The fundamentals of JavaScript"; + + const normalizedSearch = searchString.trim().toLowerCase(); + const normalizedTitle = bookTitle.toLowerCase(); + + return normalizedTitle.includes(normalizedSearch); + + } +// Example usage: + +console.log(isBookApplicable("javascript")); +// Output: true + +console.log(isBookApplicable("javascript ")); +// Output: true + +console.log(isBookApplicable("python")); +// Output: false + +console.log(isBookApplicable("JavaScript")); +// Output: true + +console.log(isBookApplicable("JAVASCRIPT")); +// Output: true From 8f35b3d8a519e9c49557b92c67fe48f780eae611 Mon Sep 17 00:00:00 2001 From: mohammedalfakih-dev Date: Thu, 29 Jan 2026 02:14:21 +0100 Subject: [PATCH 3/4] added Parse date string function --- task-2/parse-date.js | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/task-2/parse-date.js b/task-2/parse-date.js index 877a3aa..1cc0f1a 100644 --- a/task-2/parse-date.js +++ b/task-2/parse-date.js @@ -1 +1,36 @@ -// Your code here +function parseDateString(dateString) { + + const [format, datePart] = dateString.split(" "); + + const [first, second, third] = datePart.split("-"); + + + if (format === "MDY") { + return { + day: Number(second), + month: Number(first), + year: Number(third) + }; + } else { + // DMY format: Day-Month-Year + return { + day: Number(first), + month: Number(second), + year: Number(third) + }; + } +} + +// Example usage: + +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 From 1e5819a10ff7e007cc6e325e5f36eb952697562f Mon Sep 17 00:00:00 2001 From: mohammedalfakih-dev Date: Thu, 29 Jan 2026 02:41:33 +0100 Subject: [PATCH 4/4] Refactor code to follow DRY principle --- task-4/cleanup.js | 94 ++++++++++------------------------------------- 1 file changed, 19 insertions(+), 75 deletions(-) diff --git a/task-4/cleanup.js b/task-4/cleanup.js index 207523a..1be215f 100644 --- a/task-4/cleanup.js +++ b/task-4/cleanup.js @@ -1,80 +1,24 @@ -// 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 celsiusToFahrenheit(celsius) { + return (celsius * 9/5) + 32; } -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 calculateWindChill(temp, windSpeed) { + return 13.12 + 0.6215 * temp - 11.37 * Math.pow(windSpeed, 0.16) + 0.3965 * temp * Math.pow(windSpeed, 0.16); } -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 generateWeatherReport(city, tempCelsius, windSpeed) { + + const tempFahrenheit = celsiusToFahrenheit(tempCelsius); + const windChill = calculateWindChill(tempCelsius, windSpeed); + + + console.log(`\nWeather Report for ${city}:`); + console.log(`Temperature: ${tempCelsius}C (${tempFahrenheit.toFixed(1)}F)`); + console.log(`Wind Speed: ${windSpeed} km/h`); + console.log(`Wind Chill: ${windChill.toFixed(1)}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"); - -// 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 +// Example usage +generateWeatherReport("Amsterdam", 5, 20); +generateWeatherReport("London", 8, 15); +generateWeatherReport("New York", -2, 25); +generateWeatherReport("Tokyo", 12, 10); \ No newline at end of file