Tap the mole before it hides.
Reach the goal score before you run out of lives. Tap moles to score. A mole that escapes costs a life.
You write these functions. The game calls them when something happens.
onWhack()
Runs every time you tap the mole.
function onWhack() {
score = score + 1;
}onMiss()
Runs when a mole hides before you tapped it.
function onMiss() {
lives = lives - 1;
}Variables at the top of your code are the game's settings. Change a value, press Play, and see what happens.
Each step shows code you can add to the end of your game's code. A function or variable written later replaces the earlier one, so you never have to delete anything.
Tap the moles as they appear. onWhack runs on every hit, onMiss on every escape.
function onWhack() {
score = score + 1;
}Change the number to make every whack worth 3.
function onWhack() {
score = score + 3;
}A counter can switch a bonus on. After 5 whacks, every whack is worth double. Counting with a variable and testing it with if is how games track progress.
let whacks = 0;
function onWhack() {
whacks = whacks + 1;
if (whacks > 5) {
score = score + 2;
} else {
score = score + 1;
}
}// ๐จ Whack-a-Mole!
let mole = "๐น"; // who pops up
let goal = 8; // reach this score to win
let lives = 3;
let speed = 2; // 1 (slow) to 5 (fast)
function onWhack() {
score = score + 1;
}
function onMiss() {
lives = lives - 1;
}๐ ๏ธ Make your own Whack-a-Mole game
Game Studio and the full lessons are part of Premium.