Using the const Keyword (Firefox only) : Math « Development « JavaScript DHTML






Using the const Keyword (Firefox only)

  
<HTML>
<HEAD>
<TITLE>const(ant)</TITLE>
<SCRIPT LANGUAGE="JavaScript">
const FREEZING_F = 32
var cities = ["A", "B", "C", "D", "E"]
var tempsF = [3, 1, 2, 4, 5]
function showData() {
    var tableData = ""
    for (var i = 0; i < cities.length; i++) {
        tableData += "<TR><TD>" + cities[i] + "</TD><TD "
        tableData += (tempsF[i] < FREEZING_F) ? "CLASS='cold'" : ""
        tableData += ">" + tempsF[i] + "</TR>"
    }
    document.getElementById("display").innerHTML = tableData
}
</SCRIPT>
</HEAD>
<BODY onLoad="showData()">
<H1>The const keyword</H1>
<HR>
<TABLE ID="temps">
<TR><TH>City<TH>Temperature</TR>
<TBODY ID="display">
</TBODY>
</TABLE>
</BODY>
</HTML>


           
         
    
  








Related examples in the same category

1.Demo all math methods
2. Counting Rabbits (Calculating the Fibonacci Series Using a Recursive Function)
3.Math Round: round a number to the nearest whole number
4.Max number: get max number from two inputs
5.Min number: get the min number from two inputs
6.Using the Math Object
7.Math.max(inp1, inp2, inp3)
8.Math.min(inp1, inp2, inp3)
9.Math.random()
10.Math.round(rndNum)
11.Parenthesis for math statement
12.Calculate with Math.PI
13.Math Object Property Summaries