Summary - Operators
Combine arithmetic, comparison and logical operators to build a grade calculator.
Summary - Operators
In this section you met the whole family of operators: arithmetic (+ - * / % **), assignment (= += -= ++ --), comparison (== === < >) and logical (&& || !). You also saw how precedence works and how parentheses change it.
Now it is time to combine them in a real task: a grade calculator. Take an average, compare it to a threshold, print the result.
Exercise Grade calculator
exam and project are already declared. Declare finalScore. Multiply exam by 0.6, project by 0.4 and add them. Assign the result to finalScore.
Show example solution
const exam = 80;
const project = 90;
// Weighted average
let finalScore = exam * 0.6 + project * 0.4;
Test yourself
-
What is the result of (60 + 80 + 100) / 3?
console.log((60 + 80 + 100) / 3);- 60
- 100
- 80
- 240
Show answer
80 — Correct. First the sum 240, then divided by three gives 80.
-
Write the pass condition
const average = 55; const passed = average ____ 50; console.log(passed);Show answer
const average = 55; const passed = average >= 50; console.log(passed); -
Match the operator family
- +
- Add a point
- *
- Multiply by a factor
- &&
- Combine two conditions
- ++
- Bump a counter