James McGrath

Quick tips, in-depth guides, and thoughts on the future of the web

What Is an If Statement?

🧪 Concept:

An if statement lets your code make decisions. It checks whether something is true — and if it is, it runs some code.

let isRaining = true;

if (isRaining) {
console.log("Take an umbrella!");
}

The code inside the { } only runs if the condition is true.

🧰 Why It Matters:

Conditional logic is everywhere — websites, apps, games. It lets your program respond to what’s happening.

🎉 Quick Challenge:

Write a basic if statement that checks your favourite colour:

let favoriteColor = "green";

if (favoriteColor === "green") {
console.log("Nice choice!");
}

🧠 Fun Analogy:

Think of an if statement like a gate: “If this is true, open up and let the code through.”

📚 Further Reading:
MDN Docs – if…else
W3Schools – JavaScript If Else

Join us tomorrow for Day 7!

Subscribe to my feed to follow along. I’ll keep the lessons short and sweet.

What Is a Loop?

One response to “What Is an If Statement?”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.