How I can Create many answer

Viewed 39

hello i'm work for question system i want to add many answers in a one question in a one value

html

<input id="an" placeholder="test" type="text"/><a id="wo" style="display:none;">done test</a><button id="bt">Submit</button>

javascript

const an = document.getElementById("an");
const bt = document.getElementById("bt");

bt.addEventListener("click", () => {
  if (an.value.toLowerCase() === "test") { // I want create many value in here.
    bt.style.display = "none";
    an.style.display = "none";
    document.getElementById("wo").style.display = "initial";

  } else {
    bt.innerText = "Wrong!"
    bt.style.background = "red";
  }
});
1 Answers

I hope this answer is what you are looking for:

You can make an array with your answers, and then check to see if the given answer is inside the array.

const array = ['test', 'test2', 'test3'];

if (array.includes(an.value.toLowerCase() ) )
  ...

Something else, you are missing a semicolon in your else { ... }. bt.innerText = "Wrong!";

Related