JavaScript - algorithm to convert from Celsius to Fahrenheit



The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9 / 5, plus 32. You are given a variable celsius representing a temperature in Celsius. Use the variable Fahrenheit already defined and assign it to the Fahrenheit temperature equivalent to the given Celsius temperature. Use the algorithm mentioned above to help convert the Celsius temperature to Fahrenheit.


Solution Basic approach


console = { 
    log: print,
    warn: print,
    error: print
};
function convertToF(celsius) {
    var fahrenheit = celsius * (9 / 5) + 32;
    if (typeof fahrenheit !== "undefined") {
        return fahrenheit;
    } else {
        return "fahrenheit not defined";
    }
}
console.log(convertToF(30));

Output:


86

Solution not working or have any suggestions? Please send an email to [email protected]



Join Our Facebook Group


Share this example


Download Android App

download android app

Popular javascript Examples









codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube