All puzzles
Per page
F
Function ยท Shared by two onEvents

Hit or miss

Write the score variable first, then the updateScreen() function, then the hitButton button's onEvent, then the missButton button's. A hit adds 10 to score, and a miss subtracts 5 from score. Both call updateScreen() to show the score in the scoreLabel label.

After a hit and then a miss, the label shows Score: 5.

13 strips: F1 to F13

function updateScreen() {
F1
updateScreen;
F2
var score = 0;
F3
updateScreen();
F4
score = score - 5;
F5
onEvent("missButton", "click", function() {
F6
}
F7
setText("scoreLabel", "Score: " + score);
F8
});
F9
});
F10
onEvent("hitButton", "click", function() {
F11
updateScreen();
F12
score = score + 10;
F13

Answer key: F. Hit or miss

Order: F3, F1, F8, F7, F11, F13, F4, F9, F6, F5, F12, F10. Extra: F2

var score = 0;
function updateScreen() {
	setText("scoreLabel", "Score: " + score);
}
onEvent("hitButton", "click", function() {
	score = score + 10;
	updateScreen();
});
onEvent("missButton", "click", function() {
	score = score - 5;
	updateScreen();
});

Extra strip: updateScreen;. Without (), updateScreen names the function but does not call it, so a click on that button never changes the label.