Review Algorithmic Thinking by Building a Dice Game - Step 10

Tell us what’s happening:

Hi. Can’t work out why I’m getting the error:
“When your keepScoreBtn is clicked, and no options are selected, you should display an alert to the user.”
I thought if there was no option selected, then ‘checkedRadio’ would be null (therefore falsy) so putting the alert in the ‘else’ block would work. Am I wrong? Thanks

Your code so far

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

/* file: styles.css */

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

keepScoreBtn.addEventListener('click', () => {
  const checkedRadio = document.querySelector('input[type="radio"]:checked');
  console.log(checkedRadio);
  const value = checkedRadio.value; 
  const id = checkedRadio.id;
  if (checkedRadio) {
    updateScore(value, id);
    resetRadioOptions();
  } else {
    alert('Please select an option');
  }
})

// User Editable Region

Your browser information:

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

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 10

what do you think is happening here if checkedRadio is null?

1 Like