JavaScript Beginner Day 4: Conditions (if / else)

Goal of this Day

Today you will learn:

By the end, you will be able to control the flow of your program based on conditions.

Step 1: What are Conditions?

Conditions allow your program to make decisions.

Example questions:

Step 2: The if Statement

if checks if a condition is true.


let age = 20;

if (age >= 18) {
  console.log("Adult");
}

Step 3: if / else

else runs if the condition is false.


let age = 20;

if (age >= 18) {
  console.log("Adult");
} else {
  console.log("Minor");
}

Explanation:

Practice


let age = 20;

if (age >= 18) {
  console.log("Adult");
} else {
  console.log("Minor");
}

Task

Create a program that checks a score:

Example:


let score = 60;

if (score > 50) {
  console.log("Pass");
} else {
  console.log("Fail");
}