Created
January 3, 2023 13:59
-
-
Save kingvellz/233579105ed612abf394f31ee23dce0c to your computer and use it in GitHub Desktop.
formatweather report
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convertToFahrenheit(tempc){ | |
return tempc * 9/5 + 32; | |
} | |
function formatTemperatureAsString(tempc, convertToF){ | |
if (convertToF === true){ | |
return convertToFahrenheit(tempc) + "°F"; | |
} | |
else { | |
return tempc + "°C"; | |
} | |
} | |
function convertToEmojiFace(tempc){ | |
if (tempc > 30){ | |
return "🥵"; | |
} | |
else if (tempc > 12){ | |
return "😊"; | |
} | |
else { | |
return "🥶"; | |
} | |
} | |
function formatWeatherReport(cityName, tempc, showFahrenheit){ | |
if (showFahrenheit === false){ | |
return convertToEmojiFace + formatTemperatureAsString; | |
} | |
else if(tempc > 6){ | |
return tempc; | |
} | |
else{ | |
return "In" + cityName + "it is currently" + tempc * 9/5 + 32; | |
} | |
} | |
let result = formatWeatherReport('Vancouver', 6, true); | |
console.log(result);// "In Vancouver it is currently 🥶 42.8°F" | |
// Write a few more test cases here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment