Javascript

Javascript is a versatile programming language used for creating dynamic and interactive web content.

Advanced Topics

Control Flow: Loops and Conditionals

Making Decisions with Conditionals

Sometimes, you want your code to make choices. That's where if statements come in!

let temp = 25;
if (temp > 30) {
  alert("It's hot!");
} else {
  alert("It's not so hot.");
}

Doing Things Repeatedly: Loops

Loops let you run the same code multiple times, saving you from rewriting it over and over.

for (let i = 0; i < 5; i++) {
  console.log("Counting: " + i);
}

This prints numbers 0 to 4 in the console.

Why Use Control Flow?

  • Make decisions based on data
  • Repeat tasks efficiently

Real-World Uses

  • Checking if a user has permission to access a page
  • Looping through a list of messages to display them

Examples

  • Showing a special welcome if a user is a VIP

  • Counting down seconds to start a race

In a Nutshell

Conditionals help your code make decisions; loops help it repeat tasks.