Review Algorithmic Thinking by Building a Dice Game - Step 12

Tell us what’s happening:

Please, give me any hint how to set all the dice to zero

Your code so far

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

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


const resetGame = () => {
    diceValuesArr = [0, 0, 0, 0, 0];
    score = 0;
    rolls = 0;
    round = 1;
    totalScore.value = totalScore;
    scoreHistory.textContent = "";
    currentRoundRolls.textContent = rolls;
    currentRound.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();

// User Editable Region
/* file: styles.css */

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Mobile Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 12

You probably need a = 0 or something like that somewhere

1 Like

I tried the splice method, still nope. I havex also tried for each method. Console log shows me five [0, 0, 0, 0, 0] arrays, in the end of the game dice still have numbers :thinking:

I have checked the related posts, all 3 codes had just

diceValuesArr = [0,0,0,0,0]

why it doesn’t work for me? My current code is below

  let a = 0;
  diceValuesArr.splice(0, 5 , a, a, a, a, a);
 

I would not use splice at all.

This is how I’d do it

1 Like

The thing is that it was the first option that I tried and it didn’t work. Now I’ve tried it again and it still didn’t work :disappointed:

The console only says me

Your resetGame function should set each listOfAllDice element to have the text 0

I’d start looking for errors that break your function when it runs then. Have you checked the console?

Ahh, silly me, we’re mixing up the array and it’s display on the screen

1 Like

Yes, it is empty (except of the incompleted task above)

This is an HTML element

1 Like

Omg, I’m starting to understand :joy: just a sec

1 Like

Thank you for you help :pray:

My code has finally passed the test. I found how to do it in the rollDice function, using forEach and textContent methods

1 Like

Awesomeness, nice work!

1 Like