Review Algorithmic Thinking by Building a Dice Game - Step 10

Tell us what’s happening:

this code is not working the way it should, after selecting an option and the button is clicked, the else statement exectues, and i have to click the Ok button 4times and then it displays the option clicked
keepScoreBtn.addEventListener(“click”, () => {
scoreInputs.forEach((input) => {

if(input.checked){
  updateScore(input.value, input.id)
  // console.log(input.value, input.id)
  resetRadioOptions() 

} else {
alert(“Please make a selection”)
}
})

})

Your code so far

<!-- file: index.html -->

/* file: script.js */
// User Editable Region

keepScoreBtn.addEventListener("click", () => {
  scoreInputs.forEach((input) => {
    
    if(input.checked){
      updateScore(input.value, input.id)
      // console.log(input.value, input.id)
      resetRadioOptions() 
      
  } else {
    alert("Please make a selection")
  }
  })
  
 
})

// User Editable Region
/* file: styles.css */

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 10

Hi @IbraheemBos

Your logic is iterating through scoreInputs, which is why the user needs to click the Ok button four times.

Happy coding

then, the way forward

Your code has the alert statement inside the forEach callback.
If you don’t want it there, move it somewhere else.