 The if Statement
The if Statement
Imagine you are leaving your house and you look outside to check the weather. If it is raining, you decide to bring an umbrella; if it is not, you leave the umbrella at home. This everyday decision is just like how your code can make choices using an if statement. The if statement lets your program check a condition and then decide what to do next, just as you decide what to do depending on the weather.
12345let isRaining = true; if (isRaining) { console.log("It's raining. Bring an umbrella!"); }
Tak for dine kommentarer!
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat
Can you explain how the if statement works in this example?
What happens if isRaining is set to false?
Can you give another real-life example of using an if statement?
Awesome!
Completion rate improved to 7.69 The if Statement
The if Statement
Stryg for at vise menuen
Imagine you are leaving your house and you look outside to check the weather. If it is raining, you decide to bring an umbrella; if it is not, you leave the umbrella at home. This everyday decision is just like how your code can make choices using an if statement. The if statement lets your program check a condition and then decide what to do next, just as you decide what to do depending on the weather.
12345let isRaining = true; if (isRaining) { console.log("It's raining. Bring an umbrella!"); }
Tak for dine kommentarer!