Review Algorithmic Thinking by Building a Dice Game - Step 12

Tell us what’s happening:

As requested by the task, i have implemented the reset function and called the function just after the alert method in the keepScore button eventListener. however the console kept insisting the same message as below:

You should call your resetGame function after displaying the alert in your keepScoreBtn listener.
// tests completed

Your code so far

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

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



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";
  }
});


function resetGame() {
    
    listOfAllDice.forEach(die => die.textContent = '0');
    
    score = 0;
    rolls = 0;
    
    round = 1;
    totalScoreElement.textContent = score;
    
    scoreHistory.innerHTML = '';
    
    rollsElement.textContent = rolls;
    
    roundElement.textContent = round;
    
    scoreInputs.forEach(input => input.checked = false);
}


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");    
  }
  resetGame();
});





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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 12

put the resetGame call in the empty line inside this block so it gets called after the round is > 6

Thank you for your feedback, yet, same console output

please post the updated code in your reply if you still need help

here below

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");    
  }
});

Change this line to use the resetRadioOptions function

And then move the resetGame directly after the alert (inside the timeout callback). It shouldn’t matter to the execution but, just in case, move it there.

1 Like

Thank you for your feedback and assistance, was so helpful.

1 Like