Lesson not found
Lesson Progress: 0%
let sum: number = 5 + 3;
console.log(sum);
let difference: number = 10 - 4;
console.log(difference);
let product: number = 6 * 2;
console.log(product);
let quotient: number = 20 / 5;
console.log(quotient);Instructions
▲ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
Arithmetic operators let you do math with numbers in TypeScript. The four basic operators are + for addition, - for subtraction, * for multiplication, and / for division. Each variable is typed as number so TypeScript knows these are math values.
+ operator adds two numbers, so 5 + 3 produces 8.- operator takes one number away from another, so 10 - 4 produces 6.* operator multiplies numbers, so 6 * 2 produces 12./ operator divides numbers, so 20 / 5 produces 4.number typed variable, which keeps your math safe and predictable.let remainder1: number = 10 % 3;
console.log(remainder1);
let remainder2: number = 7 % 2;
console.log(remainder2);
let remainder3: number = 12 % 4;
console.log(remainder3);Instructions
▲ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
The modulo operator % gives you the remainder after dividing one number by another. It is not a percentage sign. It is a division leftover checker. You can use it to tell if a number is even, odd, or divides evenly into groups.
10 % 3 equals 1 because 3 goes into 10 three times with 1 left over.7 % 2 equals 1 because 2 goes into 7 three times with 1 leftover slice.12 % 4 equals 0 because 4 divides into 12 perfectly with nothing left over.% operator is very useful for cycling through items, checking divisibility, or keeping values within a range.let score: number = 10;
score += 5;
console.log(score);
score -= 3;
console.log(score);
score *= 2;
console.log(score);Instructions
▲ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
Assignment operators combine an arithmetic operation with the assignment = operator. They let you update a variable by performing math on its current value and storing the result back into the same variable.
score += 5 is a short way to write score = score + 5. It adds 5 to the current value, turning 10 into 15.score -= 3 takes 3 away from the current value, turning 15 into 12.score *= 2 multiplies the current value by 2, turning 12 into 24.number, so the result of each operation stays a number.let count: number = 5;
count++;
console.log(count);
count--;
console.log(count);Instructions
▲ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
The increment operator ++ adds exactly 1 to a number, and the decrement operator -- subtracts exactly 1. They are the shortest way to count up or down by one.
count++ is the same as count = count + 1 or count += 1.count++ moves the value to 6.count-- is the same as count = count - 1 or count -= 1.6 back down to 5.++ used a lot in loops and score counters to tick values up or down by one.let result: number = 5 + 3 * 2;
console.log(result);
let result2: number = (5 + 3) * 2;
console.log(result2);Instructions
▲ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
TypeScript follows the standard order of operations, just like in math class. Multiplication and division happen before addition and subtraction. You can use parentheses () to force certain parts of the expression to be calculated first.
5 + 3 * 2, multiplication happens first: 3 * 2 = 6, then 5 + 6 = 11.(5 + 3) * 2, the parentheses force addition first: 5 + 3 = 8, then 8 * 2 = 16.number variables, so TypeScript keeps your math accurate.let a: number = 15;
let b: number = 4;
let sum6: number = a + b;
let product6: number = a * b;
let remainder6: number = a % b;
console.log(sum6);
console.log(product6);
console.log(remainder6);Instructions
▲ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
You can combine multiple arithmetic operators in the same program to perform several calculations. Each result is stored in its own typed variable, and you can display them separately to see what each operation produced.
a and b are both typed as number and hold the values 15 and 4.a + b adds them together to make 19.a * b multiplies them to make 60.a % b finds the remainder of 15 divided by 4, which is 3.number type guarantees that every result stays a number, so your calculations are always reliable.Test Incomplete