Review Algorithmic Thinking by Building a Dice Game - Step 3

Tell us what’s happening:

I console.log my .die element and diceValuesArr and can see the corresponding values. Am I missing something? Or did I misunderstand what the assignment?

Your code so far

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

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

rollDiceBtn.addEventListener("click", () => {
  diceValuesArr = [];
  listOfAllDice.forEach((die) => {
    die.value = Math.floor(Math.random() * (6 - 1 + 1)) + 1;
    
    die.setAttribute("value", die.value);
    diceValuesArr.push(die.value);
    console.log(diceValuesArr);
    console.log(die);
  return;
  })})





// User Editable Region
/* file: styles.css */

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 3

Hi @paigepjwu

Build out the logic such that clicking on the rollDiceBtn generates five random numbers between 1 and 6 inclusive, sets the diceValuesArr to contain only those five numbers, and displays the numbers in order in the listOfAllDice elements.

Your code is missing the step order.

  1. generate five random numbers
  2. add them to the diceValuesArr array
  3. display each value from diceValuesArr in the listOfAllDice elements.

Pressing the Roll the dice button makes the numbers appear in each rectangle on the browser.

Happy coding

1 Like