-
Notifications
You must be signed in to change notification settings - Fork 18
Yusup R. #8
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?
Yusup R. #8
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,19 @@ | ||
| function isBookApplicable(searchString) { | ||
| // Your code here | ||
|
|
||
| const bookTitle = "The fundamentals of JavaScript"; | ||
| const normalizedTitle = bookTitle.toLowerCase(); | ||
| const normalizedSearch = searchString.trim().toLowerCase(); | ||
|
|
||
| if (normalizedTitle.includes(normalizedSearch)) { | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| console.log(isBookApplicable("javascript")); | ||
| console.log(isBookApplicable("javascript ")); | ||
| console.log(isBookApplicable("python")); | ||
| console.log(isBookApplicable("JavaScript")); | ||
| console.log(isBookApplicable("JAVASCRIPT")); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,20 @@ | ||
| // Your code here | ||
| function parseDateString(dateString) { | ||
| if (dateString.startsWith("MDY")) { | ||
| return { | ||
| day: Number(dateString.substring(7, 9)), | ||
| month: Number(dateString.substring(4, 6)), | ||
|
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 are making assumptions about the exact format of the date strings. If, for instance, the function is called without leading zeroes, the output will be wrong: console.log(parseDateString('MDY 1-21-1983'));
console.log(parseDateString('DMY 21-10-1983'));
console.log(parseDateString('MDY 3-15-2024'));
console.log(parseDateString('DMY 15-03-2024'));It would be better to use |
||
| year: Number(dateString.substring(10, 14)) | ||
| }; | ||
| } else { | ||
| return { | ||
|
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 are making the (untested) assumption here that it must be DMY if it is not MDY. This happens to be the case for the example console.logs, but may not be true in the general case. |
||
| day: Number(dateString.substring(4, 6)), | ||
| month: Number(dateString.substring(7, 9)), | ||
| year: Number(dateString.substring(10, 14)) | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| console.log(parseDateString("MDY 10-21-1983")); | ||
| console.log(parseDateString("DMY 21-10-1983")); | ||
| console.log(parseDateString("MDY 03-15-2024")); | ||
| console.log(parseDateString("DMY 15-03-2024")); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } | ||
|
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. 👍 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,80 +1,65 @@ | ||
| // 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("---"); | ||
| let windSpeed1 = 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("---"); | ||
| let windSpeed2 = 20; | ||
|
|
||
| // 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) { | ||
| let windSpeed3 = 25; | ||
|
|
||
| let cityName4 = "Dublin"; | ||
| let tempCelsius4 = 8; | ||
| let windSpeed4 = 10; | ||
|
|
||
| let cityName5 = "Edinburgh"; | ||
| let tempCelsius5 = 12; | ||
| let windSpeed5 = 18; | ||
|
|
||
|
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. It would be better if you used an array of objects to capture this data, e.g. like this: const cities = [
{ name: 'Amsterdam', tempCelsius: 22, windSpeed: 15 },
{ name: 'Berlin', tempCelsius: 15, windSpeed: 20 },
{ name: 'Copenhagen', tempCelsius: -5, windSpeed: 25 },
{ name: 'Dublin', tempCelsius: 8, windSpeed: 10 },
{ name: 'Edinburgh', tempCelsius: 12, windSpeed: 18 },
]; |
||
|
|
||
| function temperatureConversions(tempCelsius) { | ||
| let tempFahrenheit = (tempCelsius * 9 / 5) + 32; | ||
| let tempKelvin = tempCelsius + 273.15; | ||
| return { tempFahrenheit, tempKelvin }; | ||
| } | ||
|
|
||
| function weatherReport(tempCelsius) { | ||
| if (tempCelsius < 0) { | ||
| console.log("Status: Freezing"); | ||
| } else if (tempCelsius3 >= 0 && tempCelsius3 < 10) { | ||
| } else if (tempCelsius >= 0 && tempCelsius < 10) { | ||
| console.log("Status: Cold"); | ||
| } else if (tempCelsius3 >= 10 && tempCelsius3 < 20) { | ||
| } else if (tempCelsius >= 10 && tempCelsius < 20) { | ||
| console.log("Status: Mild"); | ||
| } else if (tempCelsius3 >= 20 && tempCelsius3 < 30) { | ||
| } else if (tempCelsius >= 20 && tempCelsius < 30) { | ||
| console.log("Status: Warm"); | ||
| } else { | ||
| console.log("Status: Hot"); | ||
| } | ||
| 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"); | ||
| function windChill (tempCelsius, windSpeed) { | ||
| return 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 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"); | ||
| function displayWeatherReport(cityName, tempCelsius, windSpeed) { | ||
| let { tempFahrenheit, tempKelvin } = temperatureConversions(tempCelsius); | ||
| let windChillValue = windChill(tempCelsius, windSpeed); | ||
|
|
||
| // 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(`Weather Report for ${cityName}`); | ||
| console.log(`Temperature: ${tempCelsius}°C`); | ||
| console.log(`Temperature: ${tempFahrenheit.toFixed(1)}°F`); | ||
| console.log(`Temperature: ${tempKelvin.toFixed(2)}K`); | ||
|
|
||
| weatherReport(tempCelsius); | ||
|
|
||
| console.log(`Wind chill in ${cityName}: ${windChillValue.toFixed(2)}°C`); | ||
| console.log("---"); | ||
| } | ||
|
|
||
| console.log(displayWeatherReport(cityName1, tempCelsius1, windSpeed1)); | ||
|
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 |
||
| console.log(displayWeatherReport(cityName2, tempCelsius2, windSpeed2)); | ||
| console.log(displayWeatherReport(cityName3, tempCelsius3, windSpeed3)); | ||
| console.log(displayWeatherReport(cityName4, tempCelsius4, windSpeed4)); | ||
| console.log(displayWeatherReport(cityName5, tempCelsius5, windSpeed5)); | ||
|
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. If you captured the city data in an array as I suggested above, you could now simply print the weather reports like this: for (const city of cities) {
displayWeatherReport(city.name, city.tempCelsius, city.windSpeed);
}Apart from these comments, the cleanup of the code looks good. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // Temperature conversion and weather report for City 1 | ||
|
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. This code is best left out of a PR. This not code the reviewer needs/wants to see. |
||
| 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("---"); | ||
|
|
||
| // 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("---"); | ||
|
|
||
| // 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("---"); | ||
|
|
||
| // 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"); | ||
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.
The
.includes()method already returns a boolean. No need for anifstatement.