Quotes help make search much faster. Example: "Practice Makes Perfect"

Wednesday, December 19, 2012

Codecademy Sample Solution: Codeyear Getting the Result



// sample solution to script.js

function processForm() {
   
    var temperature = Number(document.tempForm.temp.value);
    var tempType;
    var result;

    for (var i=0; i < document.tempForm.choice.length; i++) {
       
        if (document.tempForm.choice[i].checked) {
            tempType = document.tempForm.choice[i].value;
        }
    }

    if (tempType == 'fahrenheit') {
        result = temperature * 9/5 + 32;
    }
   
    else {
        result = (temperature -  32)  *  5/9;
    }
   
    // Assign the result field value here
    document.tempForm.resultField.value = result;
}

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts