Create a Js script for the English Alphabet puzzle

  • The puzzle is to check whether the selected option (Onclick) from the 4 choices given is correct or not.
  • On clicking on one option, it should indicate whether it is true or false.
    • If true → Background color green for that option
    • If False → Background color red for that option
  • There should be a Next button at the bottom of the section. On its click, it should pass to the next puzzle question.
  • The next button should only enable when the user input the correct input for the current question.

Later change as per the update requirement to include the all 26 alphabet to check in a single script.

<script>
function checkOption() {
  const isCorrect = (document.querySelector('input[name="option"]:checked').value === "1");
  const optionElem = document.querySelector('input[name="option"]:checked').parentNode;
  const submitBtn = document.getElementById("submitBtn");
  if (isCorrect) {
    optionElem.style.color = "green";
    submitBtn.disabled = false;
  } else {
    optionElem.style.color = "red";
    submitBtn.disabled = true;
  }
}
function submitAnswer() {
  window.location.href = "puzzle.html";
}
</script>

Leave a comment

Your email address will not be published. Required fields are marked *