diff --git a/task-1/book.js b/task-1/book.js index 8b49ecc..fb4de25 100644 --- a/task-1/book.js +++ b/task-1/book.js @@ -1,3 +1,21 @@ function isBookApplicable(searchString) { - // Your code here +const GetBookTitle ="The Fundamentals of JavaScript"; + + return GetBookTitle.toLowerCase().includes(searchString.trim().toLowerCase()); + } + +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 diff --git a/task-2/parse-date.js b/task-2/parse-date.js index 877a3aa..feeca6a 100644 --- a/task-2/parse-date.js +++ b/task-2/parse-date.js @@ -1 +1,32 @@ -// Your code here +function parseDateString(dateString) { +const getDateSplit = dateString.split(" ") +const getDateFormat = getDateSplit[0] +const getDate = getDateSplit[1] +const getDateValues = getDate.split("-") + +let day, month; +let year = Number(getDateValues[2]); + +if (getDateFormat === "MDY") { + month = Number(getDateValues[0]) + day = Number(getDateValues[1]) +} else if (getDateFormat === "DMY") { + day = Number(getDateValues[0]) + month = Number(getDateValues[1]) +} +return { day, month, year }; + +} + +//test cases: +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..18e4c05 --- /dev/null +++ b/task-3/date.js @@ -0,0 +1,6 @@ +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 diff --git a/task-4/cleanup.js b/task-4/cleanup.js index 207523a..2672b04 100644 --- a/task-4/cleanup.js +++ b/task-4/cleanup.js @@ -1,80 +1,45 @@ -// 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("---"); +//Math +const getFahrenheit = (celsius) => (celsius * 9 / 5) + 32; -// 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 getKelvin = (celsius) => celsius + 273.15; -// 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 getWindChill = (temp, speed) => + 13.12 + 0.6215 * temp - 11.37 * Math.pow(speed, 0.16) + 0.3965 * temp * Math.pow(speed, 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"); +//Logic +const getStatus = (celsius) => { + if (celsius < 0) return "Freezing"; + if (celsius >= 0 && celsius < 10) return "Cold"; + if (celsius >= 10 && celsius < 20) return "Mild"; + if (celsius >= 20 && celsius < 30) return "Warm"; + return "Hot"; +}; -// 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"); +//Output +const printWeatherReport = (name, temp) => { + console.log("Weather Report for " + name); + console.log("Temperature: " + temp + "°C"); + console.log("Temperature: " + getFahrenheit(temp) + "°F"); + console.log("Temperature: " + getKelvin(temp) + "K"); + console.log("Status: " + getStatus(temp)); + 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 printWindChill = (name, temp, speed) => { + console.log("Wind chill in " + name + ": " + getWindChill(temp, speed).toFixed(2) + "°C"); +}; + +//Execution +const city1 = { name: "Amsterdam", temp: 22, wind: 15 }; +const city2 = { name: "Berlin", temp: 15, wind: 20 }; +const city3 = { name: "Copenhagen", temp: -5, wind: 25 }; + +//Reports +printWeatherReport(city1.name, city1.temp); +printWeatherReport(city2.name, city2.temp); +printWeatherReport(city3.name, city3.temp); + +//Wind +printWindChill(city1.name, city1.temp, city1.wind); +printWindChill(city2.name, city2.temp, city2.wind); +printWindChill(city3.name, city3.temp, city3.wind); \ No newline at end of file