JAVASCRIPT

 Home  Computers & Internet  Web Programming JAVASCRIPT
What is Javascript?
Javascript Placement
Syntax
Reserved Words
Variables
Data Types
Escaping Characters
Concatenation
Arithmetic Operators
Assignment Operators
Comparison Operators
Boolean Operators
Conditional Operator
If Statements
Else If Statements
If Else Statements
Switch Statements
While Loops
For Loops
Do While Loops
Break Statement
Continue Statement
prompt()
alert()
Date()
Event Handlers
String Object Methods
Math Object Methods
Window Object Methods

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.

Home | Privacy Policy | Terms Of Use | Contact Us