2. Conditional Statements

2.2. An example on the use of if-else


          Suppose that you are tasked to determine if a number is odd or even. The code structure below provides a solution to this problem. (Note: Khub executes the window.alert statement in the code below)


  1. <script>
  2.  x = 5
  3.  if (x % 2 == 0){
  4.         window.alert("The number is EVEN");
  5.  }
  6.  else{
  7.         window.alert("The number is ODD");
  8.  }
  9. </script>