Review Algorithmic Thinking by Building a Dice Game - Step 12

Tell us what’s happening:

I need a more experienced set of eyes on this step.

Your code so far

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

/* file: styles.css */

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

/* I believe I have everything that is being asked on this step here, it is still saying that I need to set rolls and score to 0, I have done that already. Is it a matter of placement I have tried moving things around, still the same. */

const resetGame = () => {
  diceValuesArr = [0, 0, 0, 0, 0];
  score = 0; <---- ?
  rolls = 0; <---- ?
  round = 1;
  totalScore = 0;

  listOfAllDice.forEach((dice, index) => {
    dice.textContent = diceValuesArr[index];
});

  totalScoreText.textContent = totalScore;
  scoreHistory.innerHTML = "";

  currentRoundRollsText.textContent = rolls;
  currentRoundText.textContent = round;

  resetRadioOptions();
};

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}`);
      }, 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/126.0.0.0 Safari/537.36 Edg/126.0.0.0

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 12

Would be great if you can describe what you need help with (or what you are struggling to do at least)?

The hint is a bit mis-leading here and you can ignore that. Try to focus on the totalScore variable first.

set the totalScore text to the user’s total score,

I am unsure on what the issue is here. When I run the code it is telling me this

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

I have done that already. So idk what the issue is.

I have done that already.

const resetGame = () => {
diceValuesArr = [0, 0, 0, 0, 0];
score = 0;
rolls = 0;
round = 1;
totalScore = 0;

listOfAllDice.forEach((dice, index) => {
dice.textContent = diceValuesArr[index];
});

totalScoreText.textContent = totalScore; <------ Right here. I assume its either in the wrong spot and should be below round 1 but I tried that already still not taking it.

scoreHistory.innerHTML = “”;

Looks like you are setting it to 0 instead of " the user’s total score". Read the instructions carefully.

I’ve already tested this. You need to change this.

totalScore is an object of which you are changing the text, you can’t set it to be equal to the object itself.

totalScore = 0;

Here you set the object to equal 0, which the instructions do not ask for. You are overwriting the object created here:

const totalScore = document.getElementById("total-score");

You need to set the text to be equal to the variable score.

Okay I replaced what you suggested but the output is still saying that my resetGame function needs to set bot rolls and score to 0 and round to 1. I did that at the very top.

const resetGame = () => {
  diceValuesArr = [0, 0, 0, 0, 0];
  score = 0; <-----
  rolls = 0; <------
  round = 1; <-----
  totalScore = score;

  listOfAllDice.forEach((dice, index) => {
    dice.textContent = diceValuesArr[index];
});

  totalScoreText.textContent = score;
  scoreHistory.innerHTML = "";

Checklist below. The ones with a question mark may not be correct or done? (Just basing on your last post but maybe you didn’t include all the code)

:question: Reset all of the listOfAllDice elements to display 0 ,
:white_check_mark: update score and rolls to be 0 ,
:white_check_mark: update round to be 1 ,
:question: set the totalScore text to the user’s total score,
:white_check_mark: clear the score history by setting it to an empty string,
:question: set the currentRoundRolls text to the number of rolls,
:question: and set the currentRound text to the current round.
:question: Finally, reset all of the radio buttons to their initial states.

Sorry this is what I have so far with the corrections suggested from pkdValis.

const resetGame = () => {
  diceValuesArr = [0, 0, 0, 0, 0];
  score = 0;
  rolls = 0;
  totalScore = score; <---- I know this is the issue but I am not sure if I am doing this correctly. I know I should get this by now but im really confused still.

  round = 1;

  listOfAllDice.forEach((dice, index) => {
    dice.textContent = diceValuesArr[index];
});

  totalScoreText.textContent = score;
  scoreHistory.innerHTML = "";

  currentRoundRollsText.textContent = rolls;
  currentRoundText.textContent = round;

  resetRadioOptions();
};

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 (').

1 Like

You are overwriting the code you wrote up on line 6.

If you check, what does line 6 do?

1 Like

Consider these 3 lines and what they do, and how they work against each other.

totalScoreText does not exist.

Look at your updateScore function for how to update this object.

1 Like

Updated your post so as not to spoil the solution

The hint was definitely steering you the wrong way. Could be a candidate for a bug fix.

Glad you got it!

ill just remove it thank you for the help hbar1st!

1 Like