const answers = Array.from(document.getElementsByClassName("answer"));
const inputs = Array.from(document.getElementsByClassName("question"));
const submits = Array.from(document.getElementsByClassName("submit-answer"));
const alert = document.getElementById("alert");

submits.forEach((submit, index) => {
  submit.addEventListener("click", () => {
    const arrayOfAnswers = answers[index].innerText.split(",");
    console.log(arrayOfAnswers);
    if (arrayOfAnswers.includes(inputs[index].value)) {
      submit.style.backgroundColor = "green";
      submit.value = "✓ Μπράβο!";
      alert.innerHTML = "Συγχαρητήρια, το βρήκες";
    } else {
      submit.style.backgroundColor = "red";
      submit.value = `✕ Ξαναπροσπάθησε!`;
      submit.style.pointerEvents = "none";
      alert.innerHTML = "Λάθος, προσπάθησε ξανά";

      setTimeout(() => {
        submit.value = `Έλεγχος ✓`;
        alert.innerHTML = "";
        submit.style.backgroundColor = "rgb(0, 89, 255)";
        submit.style.pointerEvents = "auto";
      }, 4000);
    }
  });
});
