From 36a641715cc166768c8add90300e61e271e42776 Mon Sep 17 00:00:00 2001 From: saghayeg Date: Wed, 18 Nov 2026 22:49:07 +0430 Subject: [PATCH] Complete week 3 assignment --- task-1/book.js | 10 +++- task-2/parse-date.js | 30 ++++++++++- task-3/date.js | 23 +++++++++ task-4/cleanup.js | 116 +++++++++++++++++++++++++++---------------- 4 files changed, 134 insertions(+), 45 deletions(-) create mode 100644 task-3/date.js diff --git a/task-1/book.js b/task-1/book.js index 8b49ecc..382d1d2 100644 --- a/task-1/book.js +++ b/task-1/book.js @@ -1,3 +1,11 @@ function isBookApplicable(searchString) { - // Your code here + const title = "The fundamentals of JavaScript"; + const cleanSearch = searchString.trim().toLowerCase(); + return title.toLowerCase().includes(cleanSearch); } + +console.log(isBookApplicable("javascript")); +console.log(isBookApplicable("python")); +console.log(isBookApplicable("JavaScript")); +console.log(isBookApplicable("JAVASCRIPT")); +console.log(isBookApplicable(" javascript ")); diff --git a/task-2/parse-date.js b/task-2/parse-date.js index 877a3aa..4ce52e4 100644 --- a/task-2/parse-date.js +++ b/task-2/parse-date.js @@ -1 +1,29 @@ -// Your code here +function parseDateString(dateString) { + const format = dateString.substring(0, 3); + const first = dateString.substring(4, 6); + const second = dateString.substring(7, 9); + const year = dateString.substring(10, 14); + + + if (format === "MDY") { + return { + day: Number(second), + month: Number(first), + year: Number(year), + }; + } + if (format === "DMY") { + return { + day: Number(first), + month: Number(second), + year: Number(year), + }; +} +} +console.log( +parseDateString("MDY 03-15-2025") +); + +console.log( +parseDateString("DMY 15-03-2025") +); diff --git a/task-3/date.js b/task-3/date.js new file mode 100644 index 0000000..1857ca9 --- /dev/null +++ b/task-3/date.js @@ -0,0 +1,23 @@ +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 diff --git a/task-4/cleanup.js b/task-4/cleanup.js index 207523a..e399d21 100644 --- a/task-4/cleanup.js +++ b/task-4/cleanup.js @@ -1,80 +1,110 @@ -// 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) { +function convertCelsiusToFahrenheit(celsius) { + return (celsius * 9 / 5) + 32; +} + + function convertCelsiusToKelvin(celsius) { + return celsius + 273.15; + } + + function calculateWindChill(temperature, windSpeed) { + return 13.12 + 0.6215 * temperature - 11.37 * Math.pow(windSpeed, 0.16) + 0.3965 * temperature * Math.pow(windSpeed, 0.16); + } + + function printWeatherStatus(celsius) { + if (celsius < 0) { console.log("Status: Freezing"); -} else if (tempCelsius1 >= 0 && tempCelsius1 < 10) { +} else if (celsius >= 0 && celsius < 10) { console.log("Status: Cold"); -} else if (tempCelsius1 >= 10 && tempCelsius1 < 20) { +} else if (celsius >= 10 && celsius < 20) { console.log("Status: Mild"); -} else if (tempCelsius1 >= 20 && tempCelsius1 < 30) { +} else if (celsius >= 20 && celsius < 30) { console.log("Status: Warm"); } else { console.log("Status: Hot"); } + + } +// Temperature conversion and weather report for City 1 +let cityName1 = "Amsterdam"; +let tempCelsius1 = 22; +let tempFahrenheit1 = convertCelsiusToFahrenheit(tempCelsius1); +let tempKelvin1 = convertCelsiusToKelvin(tempCelsius1); +console.log("Weather Report for " + cityName1); +console.log("Temperature: " + tempCelsius1 + "°C"); +console.log("Temperature: " + tempFahrenheit1 + "°F"); +console.log("Temperature: " + tempKelvin1 + "K"); +printWeatherStatus(tempCelsius1); 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; +let tempFahrenheit2 = convertCelsiusToFahrenheit(tempCelsius2); +let tempKelvin2 = convertCelsiusToKelvin(tempCelsius2); 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"); -} +printWeatherStatus(tempCelsius2); 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; +let tempFahrenheit3 = convertCelsiusToFahrenheit(tempCelsius3); +let tempKelvin3 = convertCelsiusToKelvin(tempCelsius3); 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"); -} +printWeatherStatus(tempCelsius3); 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); +let windChill1 = calculateWindChill(tempCelsius1, windSpeed1); 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); +let windChill2 = calculateWindChill(tempCelsius2, windSpeed2); 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 +let windChill3 = calculateWindChill(tempCelsius3, windSpeed3); +console.log("Wind chill in " + cityName3 + ": " + windChill3.toFixed(2) + "°C"); + +let cityName4 = "Zurich"; +let tempCelsius4 = 4; +let tempFahrenheit4 = convertCelsiusToFahrenheit(tempCelsius4); +let tempKelvin4 = convertCelsiusToKelvin(tempCelsius4); + +console.log("Weather Report for " + cityName4); +console.log("Temperature: " + tempCelsius4 + "°C"); +console.log("Temperature: " + tempFahrenheit4 + "°F"); +console.log("Temperature: " + tempKelvin4 + "K"); +printWeatherStatus(tempCelsius4); +console.log("---"); + +// Wind chill calculation for City 4 +let windSpeed4 = 12; +let windChill4 = calculateWindChill(tempCelsius4, windSpeed4); +console.log("Wind chill in " + cityName4 + ": " + windChill4.toFixed(2) + "°C"); + +let cityName5 = "Bali"; +let tempCelsius5 = 31; +let tempFahrenheit5 = convertCelsiusToFahrenheit(tempCelsius5); +let tempKelvin5 = convertCelsiusToKelvin(tempCelsius5); + +console.log("Weather Report for " + cityName5); +console.log("Temperature: " + tempCelsius5 + "°C"); +console.log("Temperature: " + tempFahrenheit5 + "°F"); +console.log("Temperature: " + tempKelvin5 + "K"); +printWeatherStatus(tempCelsius5); +console.log("---"); + +// Wind chill calculation for City 5 +let windSpeed5 = 10; +let windChill5 = calculateWindChill(tempCelsius5, windSpeed5); +console.log("Wind chill in " + cityName5 + ": " + windChill5.toFixed(2) + "°C"); \ No newline at end of file