Java Reference
In-Depth Information
When you load this page into your browser, you should see the results shown in Figure 4-2.
figureĀ 4-2
At the top of the script block is the toCentigrade() function. It is somewhat similar to the
convertToCentigrade() function from ch4 _ example1.html ; instead of returning the converted value,
it simply writes the conversion information to the document:
function toCentigrade(degFahren) {
var degCent = 5 / 9 * (degFahren - 32);
document.write(degFahren + " Fahrenheit is " +
degCent + " Celsius.<br/>");
}
The next function, toFahrenheit() , is similar to toCentigrade() except that it converts the supplied
value to Fahrenheit. It then writes the conversion information to the document:
function toFahrenheit(degCent) {
var degFahren = 9 / 5 * degCent + 32;
document.write(degCent + " Celsius is " +
degFahren + " Fahrenheit.<br/>");
}
Search WWH ::




Custom Search