0

hi I have this code that is supposed to choose between multiple different different variable to check the answer this is the code

function handler(evt) {
  if (document.getElementById("answer").value == (result,result1,result2,result3)) {
    correct++
    document.getElementById('f').innerHTML =("correct!")
    document.getElementById('answer').value = ''

What I want it to do is check between all of the varables result,reulst1,result2,result3 I have tried a lot but I will not work. For the full code go to this link This

thanks

1 Answers1

0

You can check with || or statement

var answer = document.getElementById("answer").value;
 if (answer == result || answer == result1 || answer == result2 || answer == result3)) {
 correct++
}

another option is to add all your results to array:

var results = [result, result1, result2, result];

and to check if the value include in the array:

var answer = document.getElementById("answer").value;
results.includes(answer);

good luck

Gil Fitussi
  • 145
  • 8