Review Algorithmic Thinking by Building a Dice Game - Step 4

Tell us what’s happening:

rollDiceBtn.addEventListener(“click”, () => {
if (rolls === 3) {
alert(“You have rolled the dice three times!”);
} else {
rolls ++;
}
rollsElement.textContent = rolls;
rollDice();
});
i don’t know why i still not passing

Your code so far

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

/* file: styles.css */

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

rollDiceBtn.addEventListener("click", () => {
  if (rolls === 3) {
    alert("You have rolled the dice three times!");
  } else {
    rolls ++;
  }
  rollsElement.textContent = 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/130.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 4

1 Like

So your code looks good so far. There are just a couple of improvements needed. First, check the roll limit at the start of the function. If rolls is 3, show the alert and use return to stop the function right there. This way, one if statement is enough to handle the check and stop further execution.

Next, increment the roll count with rolls++, and update the display to show the new roll count. Finally, call rollDice() only if rolls is below 3, so the dice are rolled as long as the roll limit isn’t reached. This should work. Let us know if it does!

1 Like