Review Algorithmic Thinking by Building a Dice Game - Step 4

Tell us what’s happening:

Something weird is happening. The following code works and passes:

rollDiceBtn.addEventListener(“click”, () => {
rollDice();
rolls++;

if(rolls === 3){
alert(“You already rolled 3 times. You must select a score now.”);
rollDiceBtn.disabled = true;
}
});

But if I remove the part " rollDiceBtn.disabled = true;" the check fails. But this was only added by me as an additional idea and should not affect the check itself.

Your code so far

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

/* file: styles.css */

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

rollDiceBtn.addEventListener("click", () => {
  rollDice();
  rolls++;
  
  if(rolls === 3){
    alert("You already rolled 3 times. You must select a score now.");
  } 
});

// 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/134.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 4

You’re saying that code passes the tests? Doesn’t look like it.

EDIT: Okay. That’s a test bug. I’ll open an issue. Your code is not correct, since you would want to check to see if the user has rolled 3 times before you roll the dice again.

UPDATE: I’ve created an issue for this at: Advanced Dice Game - Step 4: Incorrect code is passing tests . Thank you for reporting this issue.

CORRECTION!: There is no issue. The tests are working as expected. When you disabled the rollDiceBtn, you prevented the user from being able to roll the dice again. So, you accomplished what was expected. The code you wrote that failed did so because the user can just “OK” the alert and continue to roll the dice. I apologize for the confusion. It took me awhile to get my head around this!