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) => {
  submit.addEventListener("click", () => {
    if (
      inputs[submits.indexOf(submit)].value ===
      answers[submits.indexOf(submit)].innerHTML
    ) {
      submit.style.backgroundColor = "green";
      submit.value = "✓ Μπράβο!";
      alert.innerHTML = "Συγχαρητήρια, το βρήκες";
    } else {
      submit.style.backgroundColor = "#e60000";
      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);
    }
  });
});
