2 - Javascript:Control Statements I - Nested if statements
The If statement can be infinitely expanded upon by nesting. Complex decision making can be achieved using this structure.
Syntax
if (condition1 is true)
{
statements to be executed if condition1 is true
if (condition a is true)
{
do something
}
else
{
do something else
}
}
else
{
statements to be executed if condition 2 is false
}
Example
<html>
<head>
<title>If else construct</title>
<script>
a = 30
if (a < 50)
{
document.write("a is less than 50")
if (a < 40)
{
document.write("<br>a is also
less than 40")
}
else
{
document.write("<br>but a is
greater than 40")
}
}
else
{
document.write("a is greater than 50")
}
</script>
</head>
</html>
So let's select and copy the above code, and experiment.