-
Notifications
You must be signed in to change notification settings - Fork 18
Diana C #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Diana C #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,9 @@ | ||
| const bookName = "The fundamentals of JavaScript"; | ||
|
|
||
| function isBookApplicable(searchString) { | ||
| // Your code here | ||
| const cleanSearch = searchString.trim().toLowerCase(); | ||
| const cleanBook = bookName.toLowerCase(); | ||
|
|
||
| const containWord = cleanBook.includes(cleanSearch); | ||
| return containWord; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,37 @@ | ||
| // Your code here | ||
| function parseDateString(dateString) { | ||
| const format = dateString.slice(0, 3); // "MDY" або "DMY" | ||
| const datePart = dateString.slice(4); // "10-21-1983" | ||
|
|
||
| const first = Number(datePart.slice(0, 2)); | ||
| const second = Number(datePart.slice(3, 5)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable names |
||
| const year = Number(datePart.slice(6, 10)); | ||
|
|
||
| let day; | ||
| let month; | ||
|
|
||
| if (format === "MDY") { | ||
| month = first; | ||
| day = second; | ||
| } else if (format === "DMY") { | ||
| day = first; | ||
| month = second; | ||
| } else { | ||
| console.log("Wrong format. Use MDY or DMY"); | ||
| return null; | ||
| } | ||
|
|
||
| return { day, month, year }; | ||
| } | ||
|
|
||
|
|
||
| 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 } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
|
|
||
|
|
||
| // convertHoursToMinutes, | ||
| // convertMinutesToHours, | ||
| // convertDaysToHours, | ||
| // convertHoursToDays, | ||
| // convertMinutesToSeconds, | ||
| // convertSecondsToMinutes | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please try to avoid using excessive comments. |
||
|
|
||
|
|
||
| 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; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You implemented all the requirements, well done! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,4 +77,56 @@ 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"); | ||
| console.log("Wind chill in " + cityName3 + ": " + windChill3.toFixed(2) + "°C"); | ||
|
|
||
|
|
||
|
|
||
|
|
||
| //DRY | ||
|
|
||
| function cityName(name) { | ||
| return `Weather Report for ${name}`; | ||
| } | ||
|
|
||
| function getStatusCelsius(celsius) { | ||
| if (celsius < 0) return "Status: Freezing"; | ||
| if (celsius < 10) return "Status: Cold"; | ||
| if (celsius < 20) return "Status: Mild"; | ||
| if (celsius < 30) return "Status: Warm"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice refactoring of status logic 👏 |
||
| return "Status: Hot"; | ||
| } | ||
|
|
||
| function getStatusFahrenheit(celsius) { | ||
| return (celsius * 9 / 5) + 32; | ||
| } | ||
|
|
||
| function getStatusKelvin(celsius) { | ||
| return celsius + 273.15; | ||
| } | ||
|
|
||
| function calculateWindChill(tempCelsius, windSpeed) { | ||
| const windSpeedPower = Math.pow(windSpeed, 0.16); | ||
|
|
||
| const windChill = | ||
| 13.12 + | ||
| 0.6215 * tempCelsius - | ||
| 11.37 * windSpeedPower + | ||
| 0.3965 * tempCelsius * windSpeedPower; | ||
|
|
||
| return windChill; | ||
| } | ||
|
|
||
| function printWindChill(city, tempCelsius, windSpeed) { | ||
| const windChill = calculateWindChill(tempCelsius, windSpeed); | ||
| console.log(`Wind chill in ${city}: ${windChill.toFixed(2)}°C`); | ||
| } | ||
|
|
||
| function printWeatherReport(cityNameValue, celsius, windSpeed) { | ||
| console.log(cityName(cityNameValue)); | ||
| console.log(`Temperature: ${celsius}°C`); | ||
| console.log(`Temperature: ${getStatusFahrenheit(celsius)}°F`); | ||
| console.log(`Temperature: ${getStatusKelvin(celsius)}K`); | ||
| console.log(getStatusCelsius(celsius)); | ||
| printWindChill(cityNameValue, celsius, windSpeed); | ||
| console.log("---"); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your refactoring is incomplete. You also need to call the |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You created clear variables with easy to read logics, well done!
But what if I provide an empty string? Or what if I call the isBookApplicable function without a parameter?
That's why, in software engineering, it's very important to first consider all the requirements and error cases that need to be handled ("Error Handling").