August 17, 2009

Javascript Tutorial 8: If-Else Statement


var num1=5;
var num2=10;

if (num1>num2)
{
alert ("correct message");
}
else
{
alert ("incorrect message");
}


Depeding on your defined variable's value, certain message will come up.


var count="counter one";
if (name=="counter one")
{
alert('this is counter number one");
}

else if (name=="counter two");
{
alert ("this is counter number two");
}
else
{
alert ("what counter number are you?");
}

A reminder that semicolon ends a statement. Test it and see what message you get.

You can change the code from there var count="counter one"; to get a new result to your variable name. Remember to always play around with these variables. Type in the same var count="counter one"; to something else and see what you get. (hope you get the "what counter number are you" message.



Powered by ScribeFire.

No comments:

Post a Comment