Lesson 5 of 10

Core Logic

Lesson 5: Functions (Coming Soon)

Functions help you organize code. We will cover this after you are comfortable with variables and if statements.

Learning Goals

Why Functions Matter

If you repeat the same steps many times, your code becomes long and hard to maintain. Functions help you write once and reuse.

console.log("Welcome, Patricia");
console.log("Welcome, Asha");
console.log("Welcome, Brian");

When we write similar lines like this, we mean the action is the same but one small value changes. A function will handle that for us in the next phase.

Function Thinking (No Syntax Yet)

Mindset: A function is like a mini machine. You give input, it does work, it returns output.

Deeper Explanation

Functions are one of the biggest upgrades in programming because they reduce repetition and improve structure. Imagine your project grows from 20 lines to 500 lines. Without reusable blocks, editing one behavior means changing many places and risking mistakes. Functions solve this by giving one place to define behavior and many places to reuse it.

Even before writing full function syntax, your brain should already ask: "Is this logic repeating?" If yes, that is function territory. This habit will make your later lessons easier and your code cleaner from the beginning.

Preparation Exercise

  1. Write three repeated print lines for three intern names.
  2. Underline the part that changes (the name).
  3. Write one sentence describing how one reusable block would help.

Homework

Create a file called function-thinking.js. Write 6 repeated lines that print report messages for different names, then add a comment explaining why a function would reduce the code.

Answer Guide
console.log("Report ready for Patricia");
console.log("Report ready for Asha");
console.log("Report ready for Brian");
console.log("Report ready for Joel");
console.log("Report ready for Fiona");
console.log("Report ready for Maria");

// A function would avoid repeating the same print pattern.
← Previous Lesson Next Lesson →