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

submits.forEach((submit) => {
  submit.addEventListener("click", () => {
    console.log(options[submits.indexOf(submit)].value);
    console.log(answers[submits.indexOf(submit)].innerHTML);

    if (
      options[submits.indexOf(submit)].value ===
      answers[submits.indexOf(submit)].innerHTML
    ) {
      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);
    }
  });
});
