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.
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 ();? 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.
Aucun commentaire:
Enregistrer un commentaire