Review Algorithmic Thinking by Building a Dice Game - Step 3

Tell us what’s happening:

rollDiceBtn.addEventListener(“click”,()=>{
let count=0;
let diceValuesArr = ;
while(diceValuesArr.length < 5 ){
let random = Math.ceil((Math.random()*6));
diceValuesArr.push(random);
listOfAllDice[count].textContent = random;
count++;
}
The task is to generate 5 random numbers for the array listOfAllDice. I have tried this code and its not working. it says that "When your rollDiceBtn is clicked, the diceValuesArr should contain five elements. I had checked youtube and the code works perfectly in the video. don’t know what’s wrong?!

Your code so far

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

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


rollDiceBtn.addEventListener("click",()=>{
      let count=0;
      let diceValuesArr = [];
      while(diceValuesArr.length < 5 ){
      let random = Math.ceil((Math.random()*6));
      listOfAllDice.push(random);
      listOfAllDice[count].textContent = diceValuesArr;
      count++;
    }


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

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 3

Hi @kskrishnalal04

  1. The .addEventListener() is not correctly closed.
  2. The while loop is not closed.
  3. The listOfAllDice will displace the first number in the first box.
    In the second box, it will display the first two numbers.
    In the third box, it will display the first three numbers, and so on.

Happy coding

first two points noted and corrected. But i dont get the third one?! I understood your point but don’t know how to rectify …
rollDiceBtn.addEventListener(“click”,()=>{
let count=0;
let diceValuesArr = ;
while(diceValuesArr.length < 5 ){
let random = Math.ceil((Math.random()*6));
diceValuesArr.push(random);
listOfAllDice[count].textcontent=random;
count++;
}
}

You changed the code so Teller’s point is no longer applicable.

Have you attempted to test your code?
The first step to fixing something is identifying the issue or problem that you need to fix.

yes, tested this code but doesnt seem to work

rollDiceBtn.addEventListener(“click”,()=>{
let count=0;
let diceValuesArr = ;
while(diceValuesArr.length < 5 ){
let random = Math.ceil((Math.random()*6));
diceValuesArr.push(random);
listOfAllDice[count].textcontent = random;
count++;
}
}

how did you test? (i don’t mean by clicking check, I mean did you actually try to pass in an array of hard-coded values and click the roll button to confirm the correct buttons are being enabled?)

Please test your code yourself and report back on what issues you found.
You should not expect someone else to do this for you.