diff --git a/task-1/book.js b/task-1/book.js index 8b49ecc..32b0d70 100644 --- a/task-1/book.js +++ b/task-1/book.js @@ -1,3 +1,11 @@ -function isBookApplicable(searchString) { - // Your code here -} +const bookTitle = "The fundamentals of JavaScript"; + +const cleanUpString = str => str.trim().toLowerCase(); + +const isBookApplicable = searchString => cleanUpString(bookTitle).includes(cleanUpString(searchString)); + +console.log(isBookApplicable("javascript")); +console.log(isBookApplicable("javascript ")); +console.log(isBookApplicable("python")); +console.log(isBookApplicable("book")); +console.log(isBookApplicable("JAVASCRIPT")); \ No newline at end of file diff --git a/task-2/parse-date.js b/task-2/parse-date.js index 877a3aa..db10e82 100644 --- a/task-2/parse-date.js +++ b/task-2/parse-date.js @@ -1 +1,36 @@ -// Your code here +const parseDateString = (input) => { + const separatorPosition = input.indexOf(" "); + if (separatorPosition === -1) return "Invalid date input"; + + const dateFormat = input.slice(0, separatorPosition); + const rawDate = input.slice(separatorPosition + 1); + + const firstHyphen = rawDate.indexOf("-"); + const secondHyphen = rawDate.lastIndexOf("-"); + + const partOne = Number(rawDate.slice(0, firstHyphen)); + const partTwo = Number(rawDate.slice(firstHyphen + 1, secondHyphen)); + const yearValue = Number(rawDate.slice(secondHyphen + 1)); + + if (isNaN(partOne) || isNaN(partTwo) || isNaN(yearValue)) { + return "Invalid date input"; + } + + if (dateFormat === "MDY") { + return { + month: partOne, + day: partTwo, + year: yearValue + }; + } + + if (dateFormat === "DMY") { + return { + day: partOne, + month: partTwo, + year: yearValue + }; + } + + return "Invalid date input"; +}; diff --git a/task-3/date.js b/task-3/date.js new file mode 100644 index 0000000..14e59c8 --- /dev/null +++ b/task-3/date.js @@ -0,0 +1,6 @@ +export const convertHoursToMinutes = (hour) => hour * 60; +export const convertMinutesToHours = (minute) => minute / 60; +export const convertDaysToHours = (days) => days * 24; +export const convertHoursToDays = (hour) => hour / 24 ; +export const convertMinutesToSeconds = (minute) => minute * 60; +export const convertSecondsToMinutes = (second) => second / 60; \ No newline at end of file diff --git a/task-4/cleanup.js b/task-4/cleanup.js index 207523a..1d2fff7 100644 --- a/task-4/cleanup.js +++ b/task-4/cleanup.js @@ -1,80 +1,46 @@ -// 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"); -} -console.log("---"); +const celsiusToFahrenheit = (celsius) => (celsius * 9 / 5) + 32; +const celsiusToKelvin = (celsius) => celsius + 273.15; -// 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"); -} -console.log("---"); +const getWeatherStatus = (celsius) => { + if (celsius < 0) return "Freezing"; + if (celsius < 10) return "Cold"; + if (celsius < 20) return "Mild"; + if (celsius < 30) return "Warm"; + return "Hot"; +}; -// 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"); -} -console.log("---"); +const calculateWindChill = (tempCelsius, windSpeed) => + 13.12 + + 0.6215 * tempCelsius + - 11.37 * Math.pow(windSpeed, 0.16) + + 0.3965 * tempCelsius * Math.pow(windSpeed, 0.16); -// 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"); +const generateWeatherReport = (cityName, tempCelsius, windSpeed) => ({ + city: cityName, + tempCelsius: tempCelsius, + tempFahrenheit: celsiusToFahrenheit(tempCelsius), + tempKelvin: celsiusToKelvin(tempCelsius), + status: getWeatherStatus(tempCelsius), + windChill: calculateWindChill(tempCelsius, windSpeed) +}); -// 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"); +const displayWeatherReport = (report) => { + console.log("Weather Report for " + report.city); + console.log("Temperature: " + report.tempCelsius + "°C"); + console.log("Temperature: " + report.tempFahrenheit.toFixed(2) + "°F"); + console.log("Temperature: " + report.tempKelvin.toFixed(2) + "K"); + console.log("Status: " + report.status); + console.log("Wind chill in " + report.city + ": " + report.windChill.toFixed(2) + "°C"); + console.log("---"); +}; -// 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 +const displayWeather = (cityName, tempCelsius, windSpeed) => { + const report = generateWeatherReport(cityName, tempCelsius, windSpeed); + displayWeatherReport(report); +}; + +displayWeather("Amsterdam", 22, 15); +displayWeather("Berlin", 15, 20); +displayWeather("Copenhagen", -5, 25); +displayWeather("Madrid", 30, 10); +displayWeather("Oslo", 5, 18); \ No newline at end of file