Review Algorithmic Thinking by Building a Dice Game - Step 12

Tell us what’s happening:

The objective was to create a reset button and then call it after the alert at the end of the game.
The hint I’m getting is:
You should call your resetGame function after displaying the alert in your keepScoreBtn listener.
I’m unable to see what I’ve done wrong.

Your code so far

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

/* file: styles.css */

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

const resetGame = () => {
    listOfAllDice.forEach(dice => {
    dice.textContent = "0";
    });

    score = 0;
    rolls = 0;
    round = 1;
    
    scoreHistory.innerHTML = "";

    totalScoreElement.textContent = score;
    rollsElement.textContent  = rolls;
    roundElement.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);
      resetGame();
    }
  } 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/130.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 12

It is super annoying but I believe they wanted the call to be directly after the alert statement and not directly after the timeout.

Okay I see, thank you!

1 Like