The radio buttons take empty values as well, we can easily move to a next choice without choosing an option for a particular question. This is the validation i prescribe for the issue.
const submitQuiz = () => { const optionInputs = document.querySelectorAll(".options"); optionInputs.forEach((input)=>{ if(!input.checked){ alert("Please select your choice."); } else{ const data = questions[index]; const ans = getAnswer(); if (ans == data.correct) { correct++; } else { incorrect++; } index++; loadQuestion(); } }); };
The radio buttons take empty values as well, we can easily move to a next choice without choosing an option for a particular question. This is the validation i prescribe for the issue.
const submitQuiz = () => { const optionInputs = document.querySelectorAll(".options"); optionInputs.forEach((input)=>{ if(!input.checked){ alert("Please select your choice."); } else{ const data = questions[index]; const ans = getAnswer(); if (ans == data.correct) { correct++; } else { incorrect++; } index++; loadQuestion(); } }); };