Whack-a-mole

First, set the browser to Full Screen view, to give this worksheet and your code as much space as possible.

Then choose either one of the two options below:

Option 1: Start this worksheet from scratch

Option 2: Continue, or view, previous work

This worksheet is copyright © Richard Pawson 2025, and protected by the Creative Commons license: Attribution-NonCommercial-NoDerivatives 4.0 International. You may freely make and distribute copies of this worksheet as is, but if you modify this worksheet you may not distribute your modified version (outside your own teaching institution) without the author's permission. Please email the author to report errors or suggest improvements.

Step 1: Introduction

Notes

Total hints used: /

Step 2: Load and exploring the starting code

, watch the following video, exploring the code alongside the video:

What is the largest and smallest result returned by the random() method?

Notes

Total hints used: /

Step 3: creating an Array

Having made the changes shown in the video and run the program, describe what the display shows?

Do any moles appear?

Notes

Total hints used: /

Step 4: making moles appear again

Having made the changes the mole should now pop up in different holes. But ...

What happens when you press a key?

Notes

Total hints used: /

Step 5: responding to the keyboard input

Make the changes shown in the video and then run the program - to show that you can now hit (and also miss!) the moles. If you find that the moles change too quickly to hit, change the speed by editing this line:
let stop be clock() + 1000 Code does not parse as Elan.
let stop be clock() + 1000 Code does not parse as Elan.
let stop be clock() + 1000 Code does not parse as Elan.
let stop be clock() + 1000 Code does not parse as Elan.
let stop be clock() + 1000 Code does not parse as Elan.
changing the value to 2000 (milliseconds), for example.

What is the main difference between how this game works and the one shown in the introductory video at the start of this worksheet?

Notes

Total hints used: /

Step 6: making multiple moles appear

Complete the changes shown in the video and confirm that 1, 2, or 3 moles appear at a time.

Notes

Total hints used: /

Step 7: review what we have learned

How can you select multiple instructions in the Elan editor?

What does 'DRY' stand for in 'the DRY principle'?

What is an 'enum' ?

What is 'dead code' within a program?

When should you use a 'for' loop?

What, in general terms, does an Array allow you to do?

How can you select multiple instructions in the Elan editor?

An Array is a simple example of a more general concept, called what?

What pieces of information must you specify when defining an Array?

If you created an array of just five elements, what would be the element numbers of the first, and last, elements?

What would be the syntax for reading the first element of an array named 'players'?

What instruction is used to change a specific element within an existing array?

Notes

Total hints used: /

Congratulations! You have completed this worksheet

If you have time available, there are two optional activities:

Continue to refine the game

Here are some ways that you might like to refine the game

Explore the source code in more depth

. Important: You don't need to understand the additional code shown in order to continue with further worksheets. However, the following video does explain the additional code for those who might want to go deeper at this stage.