Workshop › Simon Says Colors › Step 16 of 27

Check each press

What we are doing

Now the player repeats the sequence. inputAt counts how far they have got, and every press is checked against that one step: a wrong pad ends the game ('over'), a right one moves on, and after the last step the next round starts.

```js
let inputAt // how many pads of the sequence the player has repeated

  inputAt = 0

function press(pad) {
  if (state !== 'input') return
  if (pad !== sequence[inputAt]) {
    state = 'over'
    return
  }
  inputAt += 1
  if (inputAt === sequence.length) nextRound()
}
```

What it means

Your turn

  1. Change the comment of let state to include 'over', and under let timer write let inputAt.
  2. At the end of nextRound, write inputAt = 0.
  3. Under light, leave an empty line and write press.

Skills: Game states, Functions

All steps

  1. Get the canvas and the pen
  2. A dark board
  3. The first pad
  4. Two colors for every pad
  5. All four pads
  6. A function that draws
  7. Light a pad
  8. Draw again and again
  9. The sequence to remember
  10. Show the round
  11. Light a pad for a while
  12. Go dark again
  13. The computer shows a pad
  14. Show the whole sequence
  15. Watch, then your turn
  16. Check each press
  17. Play with the keyboard
  18. Which pad is at a point?
  19. Play with the mouse
  20. Progress and mistakes
  21. A function for a new game
  22. Click to retry
  23. Light up when pressed
  24. Faster and faster
  25. Save the best score
  26. Show the best score
  27. Build it yourself: no dawdling