Question:Trying to add the dice roll value from a data set every time the roll dice click is triggered and a new number is produced from a random math function.
Currently, the value is added to the array but only one value is added and the array is not incremented with each new roll value.
What is the best approach to push each new value to the array? Including a maximum of 25 additions.
The goal is to first console log each dice roll value and then eventually display them in the html as a list of 25 roll results.
Answer:You should put
let res1Arr = outside the function, since it’s now returning to empty array on every function call. Also, to avoid double results in array on every function call, you should place
forEachloop, since it’s iterating twice for each call.
If you have better answer, please add a comment about this, thank you!