Nested if else statement with parentheses in JavaScript

Description

The following code shows how to nested if else statement with parentheses.

Example


<!--from   ww w .  ja v  a2  s  .  c  o  m-->
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var temp = 0;

temp = Math.floor(Math.random() * 100) + 1;
document.write ("It's " + temp + " degrees outside. ");

if (temp < 70){
if (temp < 30){
document.write("< 30");
} else {
document.write(" between 30 and 70");
}
} else {
if (temp > 85){
document.write("> 85");
} else {
document.write("between 85 and 70");
}
}
</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Nested if else statement with parentheses in JavaScript
Home »
  Javascript Tutorial »
    Statement »
      If
Javascript Tutorial If
Compare number to boolean in if statement i...
Create an if else ladder in JavaScript
Nested if else statement in JavaScript
Nested if else statement with parentheses i...
Use Not Equal operator in if statement in J...
Use if else statement to check number range...
Use if/else to check the returning value fr...
Use if statement to compare the numbers in ...
Use if statement to compare the value again...
Use number variable directly in if statemen...
Use typeof operator in if statement in Java...