Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära 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

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 1

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Awesome!

Completion rate improved to 7.69

bookWhy Programs Need Decisions and Repetition

Svep för att visa menyn

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

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 1
some-alt