TalentJR

Lesson 9

Conditional Logic & Loops

Control flow with if, for, and while

1What is Conditional Logic?✨

Conditional logic allows your program to make decisions based on certain conditions. This means you can create different outcomes based on user input or other variables!

2Why Use Conditional Logic?🎯

  • ✓ Makes your programs interactive and responsive
  • ✓ Allows for complex decision-making
  • ✓ Essential for games, forms, and applications

3The If Statement💡

The if statement executes a block of code if its condition is true. Here’s a simple example:

💻 code
if (age >= 18) {
    console.log("You are an adult.");
}

This code checks if the variable 'age' is 18 or older and prints a message accordingly.

4Using Else and Else If🚀

You can add more conditions using else and else if. This allows for multiple paths in your code:

💻 code
if (score >= 90) {
    console.log("Grade: A");
} else if (score >= 80) {
    console.log("Grade: B");
} else {
    console.log("Grade: C or below");
}

5Loops: What Are They?🔍

Loops let you repeat a block of code multiple times. This is useful for tasks like iterating through arrays or running repetitive actions.

6The For Loop⭐

The for loop is a common way to repeat code a specific number of times. Here’s an example:

💻 code
for (let i = 0; i < 5; i++) {
    console.log("This is loop number " + i);
}

This loop will print a message five times, with the loop number included!

7The While Loop🧩

A while loop continues to run as long as its condition is true. Here's a simple example:

💻 code
let count = 0;
while (count < 5) {
    console.log("Count is: " + count);
    count++;
}

This loop will print the current count until it reaches 5.

8What You'll Build This Grade🎈

  • ✓ Interactive decision-making programs
  • ✓ Fun games with scoring systems
  • ✓ Data-driven applications
  • ✓ Dynamic content updates on web pages

🎯 Practice Challenges

Master Conditional Logic & Loops by completing all 3 difficulty levels

🟢 EASY

Conditional Logic & Loops - Easy Challenge

Start with the basics. Perfect for beginners!

🟡 MEDIUM

Conditional Logic & Loops - Medium Challenge

Get more challenging. Build your confidence!

🔴 HARD

Conditional Logic & Loops - Hard Challenge

Master this concept. Prove your skills!

🏆 Study a lesson for 2+ minutes to earn +10 TalentJR Points a day. Badges, certificates & prizes →

Ready to Master Conditional Logic & Loops? 🚀

Complete the challenges, take the quiz and keep your learning streak going!