How do I make this if statement stop after the correct answer is chosen? Do I need to change it to if else, or is there something else I can try?
if
if (!arraysEqual(answerKey, answers)) {
alert('Please Try Again');
return false;
}
if (arraysEqual(answerKey, answers)) {
$("#bin ol").append('<a href="index.html" name="modal"><img id="correct" src="images/visSelect/seq_correct.png"></a>');
return false;
}
});
if else (updated)
if (arraysEqual(answerKey, answers)) {
$("#bin ol").append('<a href="index.html" name="modal"><img id="correct" src="images/visSelect/seq_correct.png"></a>');
return false;
}else{
alert('Please Try Again');
return false;
}
if..elselooks better considering the case that you would be callingarraysEqualstwice if it returns true.In the first case, the function
arraysEqualswill be called twice if it returns true..but in the second case.. the function will be called only once in all cases and overall it looks more clear to me.