Review Algorithmic Thinking by Building a Dice Game - Step 3

Tell us what’s happening:

Task is to create Roll Dice mechanism and results for it.What is wrong?

Your code so far

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

/* file: styles.css */

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

  rollDiceBtn.addEventListener("click",()=>{function getDie(1,6){return Math.floor(Math.random()*6-1+1)}let diceValuesArr=[];for(let i=0,i < 5;i++){diceValuesArr.push(getDie(1,6))}
  listOfAllDice= console.log(diceValuesArr)});

// 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/142.0.0.0 Safari/537.36 Edg/142.0.0.0

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 3

Hi @zm17jaga

Take a look at the console.

Happy coding

rollDiceBtn.addEventListener(“click”,()=>{function getDie(min,max){return Math.floor(Math.random()*(6-1+1))}let diceValuesArr=;for( i=0;i < 5;i++){diceValuesArr.push(getDie(1,6))};console.log(diceValuesArr);

const diceElements=document.querySelectorAll(“.dice”)

diceValuesArr.forEach((diceElements,diceValuesArr)=>{diceElements.textContent=getDie[diceValuesArr]})

});

Still not working

Here are some troubleshooting steps you can follow. Focus on one test at a time:

  1. Are there any errors or messages in the console?
  2. What is the requirement of the first failing test?
  3. Check the related User Story and ensure it’s followed precisely.
  4. What line of code implements this?
  5. What is the result of the code and does it match the requirement? (Write the value of a variable to the console at that point in the code if needed.)

If this does not help you solve the problem, please reply with answers to these questions.

1.No

2. When your rollDiceBtn is clicked, your diceValuesArr array should contain five elements.

4.rollDiceBtn.addEventListener(“click”,()=>{function getDie(min,max){return Math.floor(Math.random()*(max-min+1))+min}let diceValuesArr=;for( let i=0;i < 5;i++){diceValuesArr.push(getDie(1,6))};console.log(diceValuesArr);

const diceElements=document.querySelectorAll(“.dice”)

diceElements.forEach((el,index)=>{el.textContent=diceValuesArr[index] ??“”;})

});

5.It is not being displayed.

Why not?

What does your diceValuesArr array contain?