CodeBlanks Logo Icon CodeBlanks

Summary - Operators

Combine arithmetic, comparison and nullish coalescing to build a grade calculator.

Summary - Operators

In this group you saw operators: arithmetic (+, -, *, /, %), assignment (=, +=, ++), comparison (===, ==, >, <), logical (&&, ||, !) and nullish (??, ?.).

Now there are two tasks: one for arithmetic, one for logical expressions. First recall what you learned, then apply it.

Practice Arithmetic calculation

Declare price = 50 and qty = 3. Compute total as price * qty. Call console.log(total).

Starter code

index.js
// Define price, qty and total variables
// Log total with console.log

Sample solution

index.js
const price = 50;
const qty = 3;
const total = price * qty;
console.log(total);

Expected output

150

Practice Logical expression

Declare score = 75. Compute passed as score >= 50 && score <= 100. Call console.log(passed).

Starter code

index.js
// Define score and passed variables
// Log passed with console.log

Sample solution

index.js
const score = 75;
const passed = score >= 50 && score <= 100;
console.log(passed);

Expected output

true

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Comparison reminder

Question
console.log(5 ____ 3);
Answer
console.log(5 > 3);

Explanation: > is the greater than operator.

2 Match the operators

Term Meaning
+ Arithmetic
=== Comparison
&& Logical
?? Nullish

All lessons in Beginner