Tell us what’s happening:
The code is working fine, when I click Roll the dice button it fills all the div elements correctly and the console.log shows that the array is being filled ok also, so I don’t see the problem, can anyone help?
Console output:
// running tests
3. Each of your random numbers should be between 1 and 6 inclusive.
4. Each of your .die elements should contain the corresponding value from the diceValuesArr array.
// tests completed
// console output
[ ‘2’ ]
[ ‘2’, ‘4’ ]
[ ‘2’, ‘4’, ‘4’ ]
[ ‘2’, ‘4’, ‘4’, ‘2’ ]
[ ‘2’, ‘4’, ‘4’, ‘2’, ‘4’ ]
[ ‘2’ ]
[ ‘2’, ‘1’ ]
[ ‘2’, ‘1’, ‘4’ ]
[ ‘2’, ‘1’, ‘4’, ‘2’ ]
[ ‘2’, ‘1’, ‘4’, ‘2’, ‘3’ ]
[ ‘1’ ]
[ ‘1’, ‘3’ ]
[ ‘1’, ‘3’, ‘1’ ]
[ ‘1’, ‘3’, ‘1’, ‘6’ ]
[ ‘1’, ‘3’, ‘1’, ‘6’, ‘6’ ]
[ ‘2’ ]
[ ‘2’, ‘1’ ]
[ ‘2’, ‘1’, ‘4’ ]
[ ‘2’, ‘1’, ‘4’, ‘2’ ]
[ ‘2’, ‘1’, ‘4’, ‘2’, ‘3’ ]
Your code so far
rollDiceBtn.addEventListener(“click”, () => {
diceValuesArr = ;
listOfAllDice.forEach((el) => {
el.textContent = Math.floor(Math.random() * 6) + 1;
diceValuesArr.push(el.textContent);
console.log(diceValuesArr);
});
});
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
rollDiceBtn.addEventListener("click", () => {
diceValuesArr = [];
listOfAllDice.forEach((el) => {
el.textContent = Math.floor(Math.random() * 6) + 1;
diceValuesArr.push(el.textContent);
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/131.0.0.0 Safari/537.36
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 3