2017-05-02 76 views
0

我试图运行这个简单的JavaScript代码,但没有得到所需的输出。此代码显示“您通过”而不是“您失败”。请告诉我错在哪里。它显示错误的输出?此代码有什么问题

<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> 
+1

'if(marks = 33)'this is assignment。 'if(marks === 33)'这是比较。 – dfsq

+1

当然,如果33或更高意味着通过,你不需要两个条件:'if(marks> = 33)'...... –

+0

@dfsq谢谢解决 – user5355606

回答

0

您正在使用

else if(marks=33) 

,而不是

else if(marks==33) 

您分配33 marks,而不是在别人 - 如果比较比较它

0

使用==你的商标有33

0

它在第二个陈述中被挂起。

if(marks = 33)if if(marks === 33)

相关问题