Dynamic pages, a quiz and a game
Answers are for parents and teachers.
1
The counter handler adds 3 instead of 1 (count = count + 3). What does the page show after 4 clicks?
12 (3 + 3 + 3 + 3).
2
A quiz has 4 questions and the pupil gets 3 right. Write what the page shows at the end.
Score: 3 / 4
3
Trace the ball for four steps from x = 90 with dx = 5 (the same rules as in the lesson). Write x and dx after each step.
JavaScript
1let x = 80; 2let dx = 5; 3function step() { 4 x = x + dx; 5 if (x >= 100 || x <= 0) { 6 dx = -dx; 7 } 8}
Step 1: 95, 5. Step 2: 100, -5. Step 3: 95, -5. Step 4: 90, -5.
4
This handler does not show the name. Find the mistake and write the fixed line.
JavaScript
1const box = document.getElementById("name"); 2const out = document.getElementById("out"); 3document.getElementById("hello").onclick = () => { 4 out.textContent = "Hello " + box.text; 5};
The text is read from box.text, but an input box keeps what was typed in box.value. Fixed line: out.textContent = "Hello " + box.value;
5
Write the debugging routine in four steps, and say which one you do first.
Read the error, read the code, change one thing, test again. The first step is to read the error message.