|
| ELSE IF STATEMENTS IN JAVASCRIPT
Else if statements in javascript programming are useful in that they allow for more than one condition to be tested. You can test as many conditions as you want with else if.
The general format of the if statement is:
if(certain condition)
{
execute this code;
}
else if(another condition)
{
execute another code;
}
else
{
execute yet another code;
}
Example:
var username="kyle4life";
if(username=='dolly24')
{
alert("Hello baby doll!!");
}
else if (username=='kyle4life')
{
alert("Is that you Kyle?");
}
else
{
alert("You are not welcome here!!");
}
With the above example, the script says that if the username is dolly24, then we alert a message: Hello baby doll!!
If the username is kyle4life, then we alert a message: Is that you Kyle?
Lastly, if the username is neither dolly24 nor kyle4life, then we alert a message: You are not welcome here!!
In the above script, Is that you Kyle? is outputted because username was declared as kyle4life in the first line of the code.
|
|