Workshop › Whack-a-Mole › Step 1 of 18
Moles pop out of holes; click them before they hide. Time-based state, circle hit tests, a timed round and a difficulty curve.
We are building Whack-a-Mole: moles pop out of holes and you click them before they hide. First the field: get the canvas, get its drawing pen, paint it green.
```js
const canvas = document.getElementById('game')
const ctx = canvas.getContext('2d')
ctx.fillStyle = '#65a30d'
ctx.fillRect(0, 0, canvas.width, canvas.height)
```getElementById('game') finds the canvas; getContext('2d') gives the object with the drawing commands.fillStyle picks a color, fillRect fills a rectangle: here the whole canvas.Write the lines under the comments, then press Run.
Skills: Drawing on a canvas