Javascript Function Creation convert fahrenheit to celsius

Description

Javascript Function Creation convert fahrenheit to celsius

function convertToCentigrade(degFahren) {
    let degCent = 5 / 9 * (degFahren - 32);

    return degCent;
}


let degFahren = [212, 32, -459.15];
let degCent = [];
let loopCounter;// w  ww .j  a va2  s . co  m

for (loopCounter = 0; loopCounter <= 2; loopCounter++) {
    degCent[loopCounter] = convertToCentigrade(degFahren[loopCounter]);
}

for (loopCounter = 2; loopCounter >= 0; loopCounter--) {
    console.log("Value " + loopCounter +
                   " was " + degFahren[loopCounter] +
                   " degrees Fahrenheit");

    console.log(" which is " + degCent[loopCounter] + 
                   " degrees centigrade<br />");
}



PreviousNext

Related