[英]Javascript - Why won't my incorrect answer counter increment like my correct answer counter does?
I'm trying to increment an incorrect answer counter, for some reason this isn't working.我正在尝试增加一个不正确的答案计数器,由于某种原因,这不起作用。 The correct answer counter is working fine so I've tried a similar process in making it a function but no luck.
正确答案计数器工作正常,因此我尝试了类似的过程使其成为功能,但没有运气。 I've tried adding it as separate if statement and also inside the
if (selectedAnswer == currentQuestion.answer)
statement.我尝试将它添加为单独的 if 语句,并在
if (selectedAnswer == currentQuestion.answer)
语句中添加。
You can ignore the qualifying points because that is part of another counter, I just also want a counter that increments correct and incorrect answers.您可以忽略合格点数,因为它是另一个计数器的一部分,我还想要一个计数器来增加正确和不正确的答案。 The
correctScore ()
function works fine, so why doesn't the incorrect one when I place it after correctScore ();
correctScore ()
函数工作正常,那么当我把它correctScore ();
之后时为什么不正确的呢correctScore ();
? ? Hope that makes sense.
希望这是有道理的。
let classToApply = 'incorrect-answer'; if (selectedAnswer == currentQuestion.answer) { qualifyingPointsScore(); correctScore(); classToApply = 'correct-answer'; /*selectedChoice.parentElement.classList.add(classToApply);*/ } function correctScore() { correctAnswers += 1; document.getElementById("correct-score").innerText = correctAnswers; } function incorrectScore() { incorrectAnswers += 1; document.getElementById("incorrect-score").innerText = incorrectAnswers; }
</div> <div class="scores-container"> <div class="scores-area"> <p class="scores">Correct Answers: <span id="correct-score">0</span></p> <p class="scores">Incorrect Answers: <span id="incorrect-score">0</span></p> <p class="scores">Total Questions <span id="question-counter">0</span></p> </div> </div>
Cheers in advance.提前加油。
You need to add an else part to the if-statement您需要在 if 语句中添加一个 else 部分
...
if (selectedAnswer == currentQuestion.answer) {
qualifyingPointsScore();
correctScore();
classToApply = 'correct-answer';
} else {
incorrectScore();
}
...
if (selectedAnswer == currentQuestion.answer) {
qualifyingPointsScore();
correctScore();
classToApply = 'correct-answer';
/*selectedChoice.parentElement.classList.add(classToApply);*/
}
else{
incorrectScore();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.