Summary - Operators
- Node.js course
- Beginner
- Lesson 29/116
- 5 min
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
// Define price, qty and total variables
// Log total with console.logSample solution
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
// Define score and passed variables
// Log passed with console.logSample solution
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
console.log(5 ____ 3);
console.log(5 > 3);
Explanation: > is the greater than operator.
2 Match the operators
| Term | Meaning |
|---|---|
+ |
Arithmetic |
=== |
Comparison |
&& |
Logical |
?? |
Nullish |