Nested if statement : If « Statement « JavaScript Tutorial






<html>
<head>
<title>Nested if statement</title>
<script>
var temp = 0;

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

if (temp < 70){
  if (temp < 30){
    alert("< 30");
  } else {
    alert(" between 30 and 70");
  }
} else {
  if (temp > 85){
    alert("> 85");
  } else {
    alert("between 85 and 70");
  }
}

</script>
</head>

<body>
<h3>Hit Reload to see another temperature</h3>
</body>
</html>








3.2.If
3.2.1.Conditionals
3.2.2.if...else
3.2.3.Use if statement to compare the numbers
3.2.4.Use if/else to check the returning value from a confirm dialog
3.2.5.Use if statement to check the returning value from a confirm dialog
3.2.6.Nested if statement
3.2.7.if...then...else...if