Javacript: Integer variables

This entry is part 12 of 27 in the series Javascript Tutorial

Now that we know how to manipulate the DOM or change the contents inside HTML elements, let’s use it to illustrate integer variables.

<!DOCTYPE html>
 <title>Integer variables</title>
   function updateFunction() {
    var x = 10;
    var y = 15
    var z = x + y;
    document.getElementById("int1").innerHTML = x;
    document.getElementById("int2").innerHTML = y;
    document.getElementById("int3").innerHTML = z;
   <p id="int1">Integer x</p>
   <p id="int2">Integer y</p>
   <p id="int3">Integer z = x + y</p>
  <button onclick="updateFunction()">Click Me</button>


When you declare var x = 10, it immediately knows that x is an integer.  In Javascript, we do not have to declare int x = 10.

Notice also how we change the <p> elements using the 3 ids to identify the 3 variables.

JS Fiddle.

Series Navigation<< Javascript: The getElementById() method
Javascript: Functions >>