Review Algorithmic Thinking by Building a Dice Game - Step 12

Tell us what’s happening:

I am being told “Your resetGame function should set both score and rolls to 0, and round to 1.”

As far as I can tell I’m doing exactly that. The instructions also say to call resetGame after the alert with the final score. I am also doing that. What am I missing?

Your code so far

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

/* file: styles.css */

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

const resetGame = () => {
  listOfAllDice = 0;
  score = 0;
  round = 1; 
  rolls = 0; 
  totalScoreElement.textContent = score;
  scoreHistory.innerHTML = "";
  rollsElement = rolls;
  roundElement.textContent = round;
  scoreInput.disabled;
}

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);
  }
});

rulesBtn.addEventListener("click", () => {
  isModalShowing = !isModalShowing;

  if (isModalShowing) {
    rulesBtn.textContent = "Hide rules";
    rulesContainer.style.display = "block";
  } else {
    rulesBtn.textContent = "Show rules";
    rulesContainer.style.display = "none";
  }
});

keepScoreBtn.addEventListener("click", () => {
  let selectedValue;
  let achieved;

  for (const radioButton of scoreInputs) {
    if (radioButton.checked) {
      selectedValue = radioButton.value;
      achieved = radioButton.id;
      break;
    }
  }

  if (selectedValue) {
    rolls = 0;
    round++;
    updateStats();
    resetRadioOptions();
    updateScore(selectedValue, achieved);
    if (round > 6) {
      setTimeout(() => {
        alert(`Game Over! Your total score is ${score}`);
        resetGame(); 
      }, 500);
    
    }
  } else {
    alert("Please select an option or roll the dice");
  }
});

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 12

don’t you get this error when you run the tests?
[TypeError: "listOfAllDice" is read-only]

that error is making things not work

I am seeing that. So should diceValuesArr be the one that’s 0?

So I used a forEach method over the listOfAllDice and this still didn’t work.

you can’t reassing a value to a variable declared with const, what do you want to do with listOfAllDice?

The instructions are asking me to update it to 0.

no, it is not asking to change the value of listOfAllDice, please read again:

Reset all of the listOfAllDice elements to display 0

Wait. It literally says reset to 0 lol

the value of listOfAllDice? it doesn’t say to change the variable, itsays to reset something to 0, yes, but what?

The elements? I’m not following.

yes, reset the elements to display 0.

if it doesn’t make sense to you you should review how to change what is displayed in an element

You mean with innerHTML correct?

how would you implement that?

listOfAllDice.innerHTML = 0;
It is not working

because listOfAllDice is not one element, so you can’t use innerHTML on it
check back on where it is defined

It is defined at the top of the javascript. With all due respect you are not helping me. Do I need to go somewhere else?

yes, and how it is defined?

if helping you is giving you the solution, I am not going to do that

this way is slower, but you are going to reach the solution on your own

document.querySelectorAll(“.die”);

and querySelectorAll what does it return?

All of the ‘die’ in the HTML