Angular Calculating Correct Answers And Display In Result After Multiple Answers Are Submitted In Test App
After user submitted multiple answer choices using the radio button. How can I implement result feature including the number of correctAns/totalQuestions with passing grade or fail
Solution 1:
You need to select correct answer, so n your getSelectedValues
method do like this:
for (var i = 0; i < this.selectedAnswers.length; i++) {
if(this.selectedAnswers[i] == this.allQuestions[i].correctAns)
this.correctAnswers.push(this.selectedAnswers[i]);
}
And in in your template:
<p *ngIf="correctAnswers"> Result: {{correctAnswers.length}} / {{allQuestions.length}}
<spanstyle="color:green" *ngIf="correctAnswers.length > 5"> passed </span><spanstyle="color:red" *ngIf="correctAnswers.length <= 5"> failed </span></p>
Here is working sample: StackBlitz
Post a Comment for "Angular Calculating Correct Answers And Display In Result After Multiple Answers Are Submitted In Test App"