-
Notifications
You must be signed in to change notification settings - Fork 18
Baraah A. #11
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?
Baraah A. #11
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,17 @@ | ||
| function isBookApplicable(searchString) { | ||
| // Your code here | ||
| const bookTitle ="The fundamentals of JavaScript"; | ||
|
|
||
| if (!searchString) | ||
| return false; | ||
|
|
||
| const normalSearch = searchString.trim().toLowerCase(); | ||
| const normalTitle = bookTitle.toLowerCase(); | ||
|
|
||
| return normalTitle.includes(normalSearch); | ||
|
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 named variables very clearly, well done! |
||
| } | ||
|
|
||
| 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,22 @@ | ||
| // Your code here | ||
| function parseDateString(dateString) { | ||
| const [format, datePart]= dateString.split(" ");//splet by space | ||
|
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 usage of Destructuring! |
||
|
|
||
| const [first, second, year]= datePart.split("-").map(Number); //seprator and number | ||
|
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 usage of One thing is that the variable names |
||
|
|
||
| let day , month ; | ||
|
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. Formatting is a little off. There is an extra white space before the comma and semi-colon. |
||
|
|
||
| if (format === "MDY"){ | ||
| month = first; | ||
| day = second; | ||
| } else if (format === "DMY"){ | ||
| day = first; | ||
| month = second; | ||
| } | ||
| return {day, month, year }; | ||
|
|
||
| } | ||
|
|
||
| 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")); | ||
|
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 handled all the requirements, well done! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| //hours to minutes | ||
| export function | ||
| convertHoursToMinutes(hours){ | ||
| return hours * 60 ; | ||
| } | ||
|
|
||
| //minutes to hours | ||
| export function | ||
| convertMinutesToHours(minutes){ | ||
| return minutes /60 ; | ||
| } | ||
|
|
||
| //days to hours | ||
| export function | ||
| convertDaysToHours(days){ | ||
| return days * 24; | ||
| } | ||
|
|
||
| //hours to days | ||
| export function | ||
| convertHoursToDays(hours){ | ||
| return hours/24 ; | ||
| } | ||
|
|
||
| //minutes to seconds | ||
| export function | ||
| convertMinutesToSeconds(minutes){ | ||
| return minutes*60; | ||
| } | ||
|
|
||
| //seconds to minutes | ||
| 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, but please pay attention to the code formatting. It is a good practice
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,80 +1,63 @@ | ||
| // 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"); | ||
| // Temperature functions | ||
| function celsiusToFahrenheit(celsius){ | ||
| return (celsius * 9/5)+32; | ||
| } | ||
| 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"); | ||
| function celsiusToKelvin(celsius){ | ||
| return celsius + 273.15; | ||
| } | ||
| 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"); | ||
| function getStatus(celsius){ | ||
| if(celsius<0){ | ||
| return "Freezing"; | ||
| }else if(celsius >= 0 && celsius < 10){ | ||
| return "Cold"; | ||
| }else if(celsius >= 10 && celsius < 20){ | ||
| return "Mild"; | ||
| }else if(celsius >= 20 && celsius < 30){ | ||
| return "Warm"; | ||
| }else { | ||
| return "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 | ||
| function calWindChill(celsius,windSpeed){ | ||
| return(13.12 + 0.6215 * | ||
| celsius- 11.37 * | ||
| Math.pow(windSpeed, 0.16) + | ||
| 0.3965 * celsius * Math.pow(windSpeed, 0.16)); | ||
| } | ||
| // wind chill | ||
| function printwindChill(cityName, tempCelsius,windSpeed){ | ||
| const windChill = calcWindChill(tempCelsius,windSpeed); | ||
| console.log("Wind chill in" +cityName +": " + windChill.toFixed(2) + "°C"); | ||
| } | ||
|
|
||
| //print weather report | ||
| function printWeatherReport(cityName,tempCelsius){ | ||
| const tempFahrenheit = celsiusToFahrenheit(tempCelsius); | ||
| const tempKelvin = celsiusToKelvin(tempCelsius); | ||
| const status = getWeatherStatus(tempCelsius); | ||
|
|
||
| console.log("Weather report for" + cityName); | ||
| console.log("Temperature:" + tempCelsius + "°C"); | ||
| console.log("Temperature:" + tempFahrenheit + "°F"); | ||
| console.log("Temperature:" + tempKelvin+ "K"); | ||
| console.log("Status:" + status); | ||
| } | ||
|
|
||
| //Cities | ||
| printWeatherReport("Amsterdam", 22); | ||
| printWeatherReport("Berlin", 15); | ||
| printWeatherReport("Copenhagen", -5); | ||
| printWeatherReport("Cairo", 30); | ||
| printWeatherReport("Istanbul", 6); | ||
|
|
||
|
|
||
| // 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"); | ||
| printwindChill("Amsterdam",22,15); | ||
| printwindChill("Berlin",15,20); | ||
| printwindChill("Copenhagen",-5,25); | ||
| printwindChill("Cairo",30,10); | ||
| printwindChill("Istanbul",6,15); | ||
|
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 used clear variable names and clear function names. And you implemented reusable functions in accordance with the separation of concerns principle; each function is responsible for one thing. Well done! But your code doesn't work! Did you run this code? There are two small issues. When you resolve those issues, you will see that your functions' output is not the same as the original file, and that is because of formatting the output. Pay attention to spaces and separators. |
||
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.
Nice that you handle extra white space at the beginning and the end of the search string, but what if the search string has an extra space in between words?