Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Why Programs Need Decisions and Repetition | Understanding Program Flow and Decisions
Conditional Statements and Loops in JavaScript

bookWhy Programs Need Decisions and Repetition

Imagine you are deciding what to wear in the morning. If it is raining, you choose a raincoat. If it is sunny, pick a T-shirt. This decision is based on the weather. After making your choice, you might brush your teeth, eat breakfast, and pack your bag, actions you repeat every day. Programs work similarly. They make decisions and repeat actions, allowing them to solve problems and handle many situations automatically.

12345678910
// Making a decision with if let weather = "rainy"; if (weather === "rainy") { console.log("Take an umbrella!"); } // Repeating an action with a for loop for (let day = 1; day <= 3; day++) { console.log("Brush your teeth. Day: " + day); }
copy

The code above shows how a computer can make a choice—telling you to take an umbrella if it is rainy—and how it can repeat an action, such as reminding you to brush your teeth for three days in a row. This mirrors the way you make decisions and follow routines in your daily life.

question mark

Which part of the code makes a decision, and which part repeats an action?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 1

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Suggested prompts:

Can you explain how the if statement works in this example?

What does the for loop do in the code?

Can you give more examples of decisions and repetitions in programming?

Awesome!

Completion rate improved to 7.69

bookWhy Programs Need Decisions and Repetition

Swipe um das Menü anzuzeigen

Imagine you are deciding what to wear in the morning. If it is raining, you choose a raincoat. If it is sunny, pick a T-shirt. This decision is based on the weather. After making your choice, you might brush your teeth, eat breakfast, and pack your bag, actions you repeat every day. Programs work similarly. They make decisions and repeat actions, allowing them to solve problems and handle many situations automatically.

12345678910
// Making a decision with if let weather = "rainy"; if (weather === "rainy") { console.log("Take an umbrella!"); } // Repeating an action with a for loop for (let day = 1; day <= 3; day++) { console.log("Brush your teeth. Day: " + day); }
copy

The code above shows how a computer can make a choice—telling you to take an umbrella if it is rainy—and how it can repeat an action, such as reminding you to brush your teeth for three days in a row. This mirrors the way you make decisions and follow routines in your daily life.

question mark

Which part of the code makes a decision, and which part repeats an action?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 1
some-alt