Review Algorithmic Thinking by Building a Dice Game - Step 8

Tell us what’s happening:

I think I’ve got it right? Is there something I’m doing wrong? It won’t pass, but it does exactly what is asked…
Create a resetRadioOptions function. Your function should iterate through the scoreInputs to disable them and remove the checked attribute. Your function should also remove the text from each of the scoreSpans. Finally, call this function before you roll the dice.

Your code so far

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

/* file: styles.css */

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

const resetRadioOptions = () => {
  for (let i = 0; i < diceValuesArr.length; i++){
    scoreInputs[i].disabled = true;
    scoreInputs[i].checked = false;
    scoreSpans[i].textContent = "";
  }
}

rollDiceBtn.addEventListener("click", () => {
  if (rolls === 3) {
    alert("You have made three rolls this round. Please select a score.");
  } else {

    rolls++;
    resetRadioOptions();
    rollDice();
    updateStats();
    getHighestDuplicates(diceValuesArr);
  }
});

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 8

Why are you using this loop bound?

1 Like

Wow… Now you say it hahaha. I don’t know, it has nothing to do with the scoreInputs index, but it gives the right outcome because it is also 5 ( arr.length). Think I can better use a forEach :sweat_smile:
It’s always the little things
Thank you very much!

Edit: or make i <= 6

I’d definitely not use 6. You should avoid hard coded numbers where able

1 Like

changed it to:

const resetRadioOptions = () => {
  scoreInputs.forEach((e) => {
    e.disabled = true;
    e.checked = false;
  })
  scoreSpans.forEach((e) => {
    e.textContent = "";
  })
}

Yeah, that works great and bypasses the need to index into the arrays

1 Like