Module 18: Decisions and Functions

Lesson 3 of 5 · 15–25 minutes

Functions

🏠The everyday picture

A recipe card titled "Masala chai". Once written, you don't re-explain the steps each time; you say "make masala chai", and anyone can follow it. A function is a named recipe in code.

📘What it really is

function greet() {
  console.log("Welcome to Tutor Workstation");
}

greet();
greet();

🖱️Try it

Move your level-finding code from Lesson 1 into a function called showLevel. Call it three times. Notice that you can't yet tell it which number to use; that's the next lesson.

✅Quick check

You write a function but nothing happens. What did you probably forget?

Show the answer

To call it, with its name followed by ().

Why is calculateTotal a better function name than doStuff?

Show the answer

It says what the function does, so code that uses it reads clearly.

← PreviousLoops
ProLearners Assist