# Match Day Decisions: Mastering Control Flow in JavaScript 🏟️

In programming, **Control Flow** is the order in which individual statements are executed. Normally, code runs from top to bottom, like a referee’s pre-match checklist. But sometimes, we need to take a detour based on what's happening on the pitch.

## 1\. The `if` Statement: The Referee’s Call

The `if` statement is a simple "Check." If the condition is true, the code inside the block runs. If not, it’s ignored.

**Scenario:** Checking if a player deserves a Yellow Card.

```javascript
let foulSeverity = "medium";

if (foulSeverity === "medium") {
    console.log("Referee shows a Yellow Card! 🟨");
}
```

* * *

## 2\. The `if-else` Statement: Two Outcomes

Sometimes there are only two possibilities: Win or Lose, In or Out.

**Scenario:** Is the ball in the net?

```javascript
let ballCrossedLine = true;

if (ballCrossedLine) {
    console.log("GOAL! ⚽");
} else {
    console.log("Play continues...");
}
```

* * *

## 3\. The `else if` Ladder: Multi-Decision Tactics

In a real match, things aren't always black and white. You might have multiple conditions to check.

**Scenario:** Evaluating a player's stamina.

```javascript
let stamina = 40;

if (stamina > 80) {
    console.log("Player is Sprinting! 🔥");
} else if (stamina > 30) {
    console.log("Player is Jogging. 🏃");
} else {
    console.log("Player needs a Substitution! 🪑");
}
```

* * *

## 4\. The `switch` Statement: The League Table

When you have **one variable** that could be many specific things, the `else if` ladder gets messy. That's when we use `switch`.

**Scenario:** Printing the result based on the match outcome code.

```javascript
let matchResult = "W"; 

switch (matchResult) {
    case "W":
        console.log("3 Points gained! 🏆");
        break; // Crucial! This stops the code from checking other cases.
    case "D":
        console.log("1 Point gained. 🤝");
        break;
    case "L":
        console.log("0 Points. Better luck next time. ❌");
        break;
    default:
        console.log("Result pending...");
}
```

**<mark class="bg-yellow-200 dark:bg-yellow-500/30">Pro Tip</mark>:** Always remember the `break` keyword. Without it, your code will "fall through" and execute every case after the match, which is like giving a team a Win, a Draw, and a Loss all at once!

* * *

## 5\. Switch vs. If-Else: When to use which?

<table style="min-width: 50px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><td colspan="1" rowspan="1"><p><strong>Use if-else when...</strong></p></td><td colspan="1" rowspan="1"><p><strong>Use switch when...</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p>You are checking <strong>ranges</strong> (e.g., <code>score &gt; 90</code>).</p></td><td colspan="1" rowspan="1"><p>You have <strong>fixed values</strong> (e.g., <code>day === "Monday"</code>).</p></td></tr><tr><td colspan="1" rowspan="1"><p>You have complex logic with <code>&amp;&amp;</code> or `</p></td><td colspan="1" rowspan="1"><p></p></td></tr><tr><td colspan="1" rowspan="1"><p>You only have 1 or 2 conditions.</p></td><td colspan="1" rowspan="1"><p>You want cleaner, more readable code for 4+ specific options.</p></td></tr></tbody></table>

* * *

## Day 3 Assignment: The League Reporter 📝

Open your console and write these two programs:

1.  **The Number Scout:** Write an `if-else if` ladder that checks a number and prints if it is **Positive**, **Negative**, or **Zero**.
    
2.  **The Calendar:** Use a `switch` statement that takes a number (1-7) and prints the corresponding **Day of the Week** (e.g., 1 = Monday).
    

**Which structure did you find easier to write? Tell me in the comments!**
