Workshop › Simon Says Colors › Step 9 of 27
The sequence is the list of pads the player must repeat. It starts empty; every round nextRound adds one random pad
(0 to 3) to its end.
```js
let sequence = [] // the pads to repeat, growing by one every round
function nextRound() {
sequence.push(Math.floor(Math.random() * 4))
}
nextRound()
requestAnimationFrame(loop)
```[] is an empty array; push adds an item to its end.Math.random() is a random number from 0 up to 1; times 4, rounded down, it is 0, 1, 2 or 3: a random pad.nextRound() at the bottom adds the first pad before the loop starts.let lit, write the sequence line.function draw, write nextRound and an empty line.nextRound() above requestAnimationFrame(loop).Skills: Arrays and objects
← Draw again and again Show the round →