When answering multiple-choice questions, it is important to select ALL of the correct options in order to increase your score. Selecting just one correct answer and then marking another as incorrect will still result in a score increase of 1, which is not ideal. The score should only increase when all correct answers are given. Similarly, if you initially select an incorrect answer followed by all correct answers, or a correct answer followed by an incorrect one and then another correct answer, the score should still increase. Single-answer questions should also increase the score as expected. Can you please help resolve this issue? You can view my app here: https://stackblitz.com/edit/angular-10-quiz-app
The current code snippet responsible for increasing the score can be found in src -> app -> containers -> quiz -> quiz.component.ts under the method checkIfAnsweredCorrectly:
checkIfAnsweredCorrectly() {
if (this.question) {
const correctAnswerFound = this.answers.find((answer) => {
return this.question.options &&
this.question.options[answer] &&
this.question.options[answer]['selected'] &&
this.question.options[answer]['correct'];
});
const answers = this.answers && this.answers.length > 0 ? this.answers.map((answer) => answer + 1) : [];
this.quizService.userAnswers.push(this.answers && this.answers.length > 0 ? answers : this.answers);
if (correctAnswerFound > -1 &&
answers.length === this.quizService.numberOfCorrectAnswers) {
this.sendCorrectCountToQuizService(this.correctCount + 1);
}
}
}