我试图运行这个简单的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>
'if(marks = 33)'this is assignment。 'if(marks === 33)'这是比较。 – dfsq
当然,如果33或更高意味着通过,你不需要两个条件:'if(marks> = 33)'...... –
@dfsq谢谢解决 – user5355606