Review Algorithmic Thinking by Building a Dice Game - Step 4

Tell us what’s happening:

My code is performing the tasks that fCC is asking, however it won’t accept my answer.
I’ve also noticed an issue where the ‘Roll the dice’ button may be clicked three times before an alert appears, however when I click to close the alert, the dice roll function occurs for a forth time. How can I stop it from generating another set of numbers when dismissing the alert?

Your code so far

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

/* file: styles.css */

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

rollDiceBtn.addEventListener("click", () => {
  rollDice();
  if (rolls === 3) {
    alert("You have made three roles this round. Please select a score.");
  } else {
    rolls++;
    rollDice();
  }
});

// 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

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 4

What is the first thing that happens when the button is clicked?
(read the code you wrote and check)

The function is carried out and 5 dice are rolled and displayed on the preview, as expected.

I mean in the code (not in the preview).
What is the first thing that executes in your code when the button is clicked.
This:

Now the question is: why?
Why is this your first line?

3 Likes

this was the solution for me thank you

1 Like

That was exactly it, of course!! Thank you for your help, I deleted the line and it’s working perfectly now :slight_smile:

1 Like