Review Algorithmic Thinking by Building a Dice Game - Step 12

Tell us what’s happening:

Actually I am getting the error

Your resetGame function should set both score and rolls to 0, and round to 1.

can someone help me that what mistake I am makking?

Your code so far

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

/* file: styles.css */

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



function resetGame() {
    listOfAllDice.forEach(die => die.text = '0');
    score = 0;
    rolls = 0;
    round = 1;
    totalScore.text = userTotalScore;
    scoreHistory = '';
    currentRoundRolls.text = rolls;
    currentRound.text = round;
    resetRadioButtons();
}


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;
  resetGame();
  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}`);
      }, 500);

    }
  } else {
    alert("Please select an option or roll the dice");
  }
});

// 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/127.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 12

did you mean to write textContent instead of text?

also here. The totalScore.textContent should be set to score

I’ve updated my code and my updated code is

function resetGame() {
listOfAllDice.forEach(die => die.text = ‘0’);
score = 0;
rolls = 0;
round = 1;
totalScore.textContent = userTotalScore;
scoreHistory = ‘’;
currentRoundRolls.textContent = rolls;
currentRound.textContent = round;
resetRadioButtons();
}

but the error still comes and error states that

Your resetGame function should set both score and rolls to 0 , and round to 1 .

ReferenceError: userTotalScore is not defined

function resetGame() {
listOfAllDice.forEach(die => die.text = ‘0’);
score = 0;
rolls = 0;
round = 1;
totalScore.textContent = userTotalScore;
scoreHistory = ‘’;
currentRoundRolls.textContent = rolls;
currentRound.textContent = round;
resetRadioButtons();
}

did this but shows same error and also i have reset the lesson but still shows the same error

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

please fix this (your new code still has the same mistake with the wrong variable userTotalScore)

1 Like

console.log() all your variables and print them. This is a good and common troubleshooting technique. You’ll see that one of your variables does not exist.

1 Like

I have made changes!

your new code is still having the wrong variable name.
Change this variable userTotalScore to score.

Brother i did not mentioned here! I said the have made changes in my code now it is working fine! I did not mention updated code here previously I have reply to other person kindly check that!

Yay! got my mistake and now it is solved!

Thanks!

okay, to avoid confusion, you should mark the post that helped you solve the problem as ‘the solution’ in future. You do this by selecting the checkbox underneath the helpful post.