Page 362 - Webapplication11_C11_Flipbook
P. 362
Lab Assignment ‘n Activity #Critical Thinking
Find the error in the following code and rewrite the code.
if(age > 18)
{
document('You are eligible to vote');
}
else
{
document('Not eligible to vote');
}
Nested if Statement
JavaScript allows the nested if statement. This means the if indented block inside another if…else indented block. The
second nested if indented block will run only when the first if condition evaluates to be true. The syntax of nested if
statement is shown below:
if(condition 1)
{
if(condition 2)
{
//When the condition 1 and condition 2 is true then block of code to be executed.
}
else
{
//When the condition 1 is true and condition 2 is false then block of code to
be executed.
}
Flow diagram:
condition True
Statement1
1
False
condition True
Statement2
2
False
condition True
Statement3
3
False
Statements outside the if-else if-else block
360 Touchpad Web Applications-XI

