Else if statement :- genius student


  • First check the if(condition) and if it is false, the next else if condition executed and if both of the above condition is false, the else block execute.
  • else if and else block are optional.
Syntax
if (condition1) {
    //block of code to be executed if condition1 is true
} else if (condition2) {
    //block of code to be executed if the condition1 is false and condition2 is true
} else {
    //block of code to be executed if the condition1 is false and condition2 is false
}

Code:-

<!DOCTYPE html>
<html>

<head>
 <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>

 <h1>else if</h1>

 <input type="button" onclick="chek();" value="else if">
 <script>
  function chek()
  {
   if (30 > 40) //This condition is false so next else if part is execute
   {
    alert("30 is big");
   }
   else if (30 == 40) //This condition also false so execute else part
   {
    alert("30 and 40 is equal");

   }
   else
   {
    alert("possible for 40 is big");
   }

  }
 </script>

</body>

</html>
Else if statement :- genius student Else if statement :- genius student Reviewed by Network security on October 14, 2019 Rating: 5

No comments:

Useful Information

Powered by Blogger.