Menu Profile JavaScript Algorithms and Data Structures Review Algorithmic Thinking by Building a Dice Game Step 12

Hello ,

Here is my code for the step 12
I receive the message " You should call your resetGame function after displaying the alert in your keepScoreBtn listener."

The function is already called someone can help please ?

const resetGame = () => {
listOfAllDice.forEach(element => element.textContent = 0);
score = 0;
rolls = 0;
round = 1;

scoreHistory.textContent = “”;
rollsElement.textContent = rolls;
totalScoreElement.textContent = score;
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”);
}
});

Hi there. You aren’t calling the resetGame function after the alert function. You have called it after setTimeout function.

Thank you .Now it is working.

1 Like