【发布时间】:2021-04-28 11:43:20
【问题描述】:
我在 JavaScript 上进行了 IQ 测试,并给出了分数的条件,在某些范围内它显示不同的 IQ 分数,但无论有多少正确答案,它都只显示最后一个条件。我已经尝试了很多东西,但没有任何效果。我需要尽快提交这个项目。如果有人可以提供帮助,我将不胜感激。我在下面附上了相关部分的代码。
function displayResult()
{
var score = $('<p>',{id: 'question'});
var correct = 0;
for (var i = 0; i < selectOptions.length; i++)
{
if (selectOptions[i] === allQuestions[i].answer) {
correct++ ;
console.log(correct)
}
}
if (correct < 5){
score.append("Your IQ Score lies in the range of 70-79 which is classified as Bordeline. 6.7% of the world's population falls in this range.<br> <img id='img1' src='BORDERLINE.png' height=90px width=500px/></br>");
}else if (correct>=5 && correct < 10){
score.append("Your IQ Score lies in the range of 80-89 which is classified as low average. 16.1% of the world's population falls in this range. <br> <img id='img1' src='LOW AVERAGE.png' height=90px width=500px/></br> ");
}else if (correct >= 10 && correct < 20){
score.append("Your IQ Score lies in the range of 90-109 which is
classified as average. 50% of the world's population falls in this range. <br>
<img id='img1' src='AVERAGE.png' height=90px width=500px/></br>");
}else if (correct >= 20 && correct <=25){
score.append("Your IQ Score lies in the range of 110-119 which is
classified as high average. 16.1% of the world's population falls in
this range. <br> <img id='img1' src='HIGH AVERAGE.png' height=90px
width=500px/></br>");
}else if(correct >= 25 && correct <=30) {
score.append("Your IQ Score lies in the range of 119-129 which is
classified as superior. 6.7% of the world's population falls in this
range.
<br> <img id='img1' src='SUPERIOR.png' height=90px width=500px/>
</br>"); }
return score;
}
<html>
<head>
<title>Make Quiz Website</title>
<link rel="stylesheet" href="quiz.css">
<link href="https://fonts.googleapis.com/css?family=Josefin+Sans" rel="stylesheet">
</head>
<body>
<div id="container">
<h1>Quiz Website Using JavaScript</h1>
<br/>
<div id="quiz"></div>
<p id="countdown">30:00</p></h1>
<div class="button" id="next"><a href="#">Next</a></div>
<div class="button" id="prev"><a href="#">Prev</a></div>
</div>
<script src="https://code.jquery.com/jquery-3.4.0.min.js"></script>
<script src="quiz.js"></script>
</body>
</html>
【问题讨论】:
-
您的第一个条件
correct == 0 && correct < 5似乎需要使用||而不是&&,因为如果correct == 0,那么它已经是<5。 -
if (正确 = 0 && 正确
-
是的,我的意思是正确的>=0
标签: javascript html jquery if-statement conditional-statements