Walking into a side room (the function), doing some work with what you brought in, and carrying something back out with you (the return value) when you leave.
A function is a named block of code you can reuse any time you need it. It can take inputs (called parameters), and it can hand a value back using return. Forget return, and the function just quietly gives back nothing (undefined).
function name(parameter) {
return value;
}function doubleScore(points) {
return points * 2;
}
console.log(doubleScore(10));doubleScore takes one input, points. Calling doubleScore(10) runs the function with points set to 10, which computes 10 * 2 and hands 20 back out - console.log then prints that returned value.
function greetPlayer(name) {
return `Welcome, ${name}!`;
}
console.log(greetPlayer("Zoe"));Functions can return text too, not just numbers - here it builds and hands back a whole greeting sentence using the name that was passed in.
Mistake 1: forgetting return - a function without it still runs, but silently gives back undefined instead of the value you expected, even if it printed something with console.log along the way. Mistake 2: mixing up console.log and return - console.log only shows something on screen, it doesn't hand a value back to the code that called the function. Mistake 3: calling a function with the wrong number of arguments - addBonus(50) when addBonus expects TWO parameters doesn't crash, it just quietly sets the missing one (bonus) to undefined, and any math with it becomes NaN instead of a real number.
In the app this lesson continues with the animated explanation, spoken aloud, and then the practice: Complete addBonus so it returns score + bonus, then call addBonus(50, 25) and print the result. The editor runs your child’s real code and checks the result, with their coding buddy reacting to what they wrote.
Try it free