11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Additional logic can be applied with an else statement. When the condition of the first statement<br />

is not met, the code in the else statement will be executed:<br />

if (expression)<br />

else<br />

statement or block<br />

statement or block<br />

Given this syntax, we could expand the previous example as follows:<br />

var x = 5;<br />

if (x >> 1)<br />

{<br />

}<br />

else<br />

{<br />

}<br />

alert("x is greater than 1.");<br />

alert("Yes x really is greater than 1.");<br />

alert("x is less than 1.");<br />

alert("This example is getting old.");<br />

alert("moving on ...");<br />

More advanced logic can be added using else if clauses:<br />

if (expression1)<br />

statement or block

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!