Skip to content

Instantly share code, notes, and snippets.

@kingvellz
Created January 3, 2023 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kingvellz/233579105ed612abf394f31ee23dce0c to your computer and use it in GitHub Desktop.
Save kingvellz/233579105ed612abf394f31ee23dce0c to your computer and use it in GitHub Desktop.
formatweather report
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