Hi all, I’m working on a small Angular project. Its a quiz app which uses a array called answers to validate the input answer but for some reason I’m failing to get the logic to display the dialog boxes accordingly. the code below is within a submit function. the problem I have is that the loop overwrites itself and even when the answer is found it will still execute the else statement.
let type = (<HTMLInputElement>document.getElementById('a')).value;
this.test = type;
for(let i = 0; i < this.answers.length; i++){
if(this.test == this.answers[i]){
this.dialog.open(SuccessboxComponent);
}else{
this.dialog.open(FailboxComponent);
}
}
I initialized a variable called result to an empty string then used a break in order to force the loop to stop if it finds the right answer in the array instead of continuing and eventually overwriting itself, i don’t believe its the most efficient way but it gets the job done with no error.