Lesson 3 of 15
Lesson Progress: 0%
let sum = 5 + 3;
console.log(sum); // the answer should be 8
let result = 10 - 4;
console.log(result); // the answer should be 6
let product = 6 * 2;
console.log(product); // 12
let quotient = 20 / 5;
console.log(quotient); // 4Instructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
+, -, *, and / that help us do math.+ operator adds numbers together, like 5 + 3 makes 8.- operator takes one number away from another, like 10 - 4 makes 6.* operator multiplies numbers, like 6 * 2 makes 12./ operator divides numbers, like 20 / 5 makes 4.let remainder = 10 % 3;
console.log(remainder); // the answer should be 1
// Sharing 7 slices of pizza with 2 people
let pizzaLeftover = 7 % 2;
console.log(pizzaLeftover); // the answer should be 1
// Putting 12 toys into 4 equal boxes
let toyLeftover = 12 % 4;
console.log(toyLeftover); // 0Instructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
% operator is called the modulo operator, and it gives you the leftover after dividing.% to check if a number is even or odd, because even numbers have no leftovers.10 % 3 gives 1, because 3 goes into 10 three times with 1 left over.7 % 2 gives 1, showing there is one slice left after sharing.12 % 4 gives 0, meaning everything divides evenly with no leftovers.let x = 7;
console.log(x); // the answer should be 7
// Keeping track of a player's lives
let lives = 3;
console.log(lives); // the answer should be 3
// Counting how many gold coins you found
let coins = 50;
console.log(coins); // the answer should be 50Instructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
= operator is used to give a value to a variable, like putting something into a box.let x = 7; stores the number 7 so we can use it later.let lives = 3; keeps track of how many lives a player has.let coins = 50; stores how many coins were collected.console.log(5 == 5); // true
// Example 1: Comparing a number and a string
console.log(10 == 10); // true
console.log(5 == "5"); // true
// Example 1: Comparing a number and a string
console.log(10 == "10"); // true
// Example 2: Comparing the number zero and an empty-looking string
console.log(0 == ""); // trueInstructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
== operator checks if two values are equal, even if they are different types.10 == 10 is true because both values are the same number.== operator is different from ===, because === also checks the type.== can be confusing, like 5 == "5" being true even though one is a number and one is text.0 == "" being true because it treats them as equal.const b = 5;
console.log(5 === b); // true
const c = 10;
console.log(10 === c); // true
console.log(5 === "5"); // false
// Example 1: Strict check between a number and a string
console.log(10 === "10"); // false
// Example 2: Strict check between a number and a boolean
console.log(1 === true); // falseInstructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
=== is a strict judge that requires things to be exactly the same.false for 10 === "10" because a plain number is not the same as a word.let count = 5;
count++;
console.log(count); // 6
// Giving a player a point in a video game
let score = 10;
score++;
console.log(score); // 11
// Counting how many levels you finished
let level = 1;
level++;
console.log(level); // 2Instructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
++ symbol is a shortcut that tells the computer to "add one" to your number.++ after the name to grow the number.let count = 5;
count--;
console.log(count); // 4
// Losing a life in a game
let hearts = 3;
hearts--;
console.log(hearts); // 2
// Counting down the remaining cookies
let cookiesInJar = 10;
cookiesInJar--;
console.log(cookiesInJar); // 9Instructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
-- symbol is a quick shortcut that tells the computer to "subtract one" from your number.const guests = 5;
const seats = 4;
console.log(guests > seats);
// Checking if you have enough gold to buy a sword
const swordPrice = 10;
const myGold = 8;
console.log(myGold > swordPrice);
// Checking if a car can fit under a bridge
const bridgeHeight = 12;
const carHeight = 9;
console.log(carHeight < bridgeHeight);Instructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
< and > symbols are like "Comparison Crocodiles" that check which number is bigger.true or false answer based on whether the rule you wrote is correct.const guests = 5;
const meals = 4;
console.log(guests > meals);
// Checking if you have enough fuel for your rocket
const fuelNeeded = 100;
const fuelLevel = 150;
console.log(fuelLevel > fuelNeeded);
// Checking if your backpack is too heavy
const maxWeight = 20;
const currentWeight = 25;
console.log(currentWeight > maxWeight);Instructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
> symbol is like a hungry crocodile that always wants to open its mouth toward the bigger number.true answer.const leashes = 7;
const puppies = 3;
console.log(leashes >= puppies);
// Checking if you have enough fuel for your rocket
const fuelNeeded = 100;
const fuelLevel = 150;
console.log(fuelLevel >= fuelNeeded);
// Checking if your backpack is too heavy
const maxWeight = 20;
const currentWeight = 25;
console.log(currentWeight >= maxWeight);Instructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
>= symbol checks if the first number is bigger than OR exactly the same as the second one.true as long as you have enough for everyone, even if it's a perfect fit.const cars = 2;
const parkingSpaces = 5;
console.log(cars <= parkingSpaces);
// Can your group fit on a bench made for 3 people?
const people = 5;
const benchSeats = 3;
console.log(people <= benchSeats); // true (A perfect fit!)
// Is your suitcase light enough for the airplane?
const maxWeight = 50;
const myBagWeight = 42;
console.log(myBagWeight <= maxWeight); // true (It's under the limit!)Instructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
<= symbol checks if a number is smaller than or exactly equal to another number.true as long as you don't go over the maximum allowed amount.let cars = 2;
cars += 1;
console.log(cars);
cars += 3;
console.log(cars)
// Example 1: Gaining experience points (XP) in a game
let xp = 100;
xp += 50;
console.log(xp); // 150
// Example 2: Adding items to a shopping cart
let cartTotal = 2;
cartTotal += 1;
console.log(cartTotal); // 3
cartTotal += 5;
console.log(cartTotal); // 8Instructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
+= symbol is a power-up that adds a new number to the current total and saves it.cars = cars + 1 by combining the math and the saving into one step.let cars = 25;
cars -= 1;
console.log(cars);
cars -= 3;
console.log(cars);
// Example 1: Spending gold coins in a shop
let gold = 100;
gold -= 20;
console.log(gold); // 80
// Example 2: Fuel leaking from a gas tank
let fuel = 50;
fuel -= 5;
console.log(fuel); // 45
fuel -= 10;
console.log(fuel); // 35Instructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
-= symbol is a shortcut that subtracts a number from the total and saves the new result.Test Incomplete