A Button Click Moment: Coding lesson for kids
In “A Button Click Moment”, children learn about <button onclick="sayHi()">Click me</button>, function sayHi() { alert("Hi!"); } and onclick="sayHi()" but no sayHi() exists.
<button onclick="sayHi()">Click me</button>: onclick names the function that runs the moment this button is clicked.
function sayHi() { alert("Hi!"); }: This is the function onclick points to — it runs when the button is clicked.
onclick="sayHi()" but no sayHi() exists: The name has to match EXACTLY — if onclick points to a function that was never defined (or got renamed), clicking the button throws a ReferenceError.
This lesson is part of JavaScript in Coding at Pearls Valley Academy — What makes a webpage actually do something.
Each lesson starts with a short narrated, animated explanation, then hands-on practice. A wrong answer gets a gentle hint, never a penalty, and children earn stars and pearls as they go.