<HTML>

<HEAD>
<TITLE>if statement example</TITLE>
</HEAD>

<BODY>

<SCRIPT>
/*This script will demonstrate an if statement*/


var numstr1 = null, numstr2 = null; //declearing and intializing strings to null
var x =0, y = 0, z = 0 ;// declaring and intializing integers


numstr1 = prompt ("Please enter an Integer","");//inputting a real number
numstr2 = prompt ("Please enter an Integer","");//inputting a real number


x = parseInt(numstr1);//converting the first string to an integer.
y = parseInt(numstr2);// converting the second string to a float.
z = 25;

y = x + z; // changing the value of y
x = x + y; // changing the value of x
z = x + y; // changing the value of z

alert("\nx =" +x+ " \ny = " +y+ " \nz = " +z);

if (x == 37) alert("Hello");

if (x != 37) alert("###");

if ( y < z) alert ("***");

if (x > y) alert ("yes"); else alert ("no");


if (x <= z)
{
z = z + 2;
alert("\nz=" +z);
}
else
{
z = z - 2;
alert("\nz=" +z);
}


</SCRIPT>
</BODY>
</HTML>

 

Run Script
Sample Output