0

I'm trying to run this simple javascript code but doesn't get desired output. This code showing "You are pass" instead of "You are fail". Please tell where im wrong.

<html>
  <head>
    <title>
      If else if and else use
    </title>
  </head>
<body>
  <script>
  function ifelseifelse() {
  var marks=32;
  if (marks>33){
  alert("You are Pass");
  }
  else if(marks=33)
  {
  alert("You are pass");
  }
  else{
  alert("You are fail");
  }

  }
  </script>
  <button type = "button" onclick="ifelseifelse()" >If else-if if</button> 
</body>
</html>

3 Answers3

0

You are using

else if(marks=33)

instead of

else if(marks==33)

You are assigning 33 to marks instead of comparing it

ArmaGeddON
  • 339
  • 1
  • 10
0

Use == in the else-if to compare your marks with 33

0

it's getting hung up at the second statement.

if(marks=33) should be if(marks === 33)

Wazimshizm
  • 73
  • 2
  • 10