Order of operations with brackets

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Order of operations with brackets

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does console.log(2 + 3 * 4) print?
A 20
B 14
2. Which line correctly works out the average of a and b?
A let avg = (a + b) / 2;
B let avg = a + b / 2;
3. If a = 6 and b = 10, what does a + b / 2 give?
A 8
B 11
4. What does console.log((2 + 3) * 4) print?
A 20
B 14
5. What does 2 * (3 + (4 - 1)) give?
A 12
B 10

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1let avg = (a + b) / 2; AWorks left to right because - is on the same level, so it does 20 - 6 = 14 and then 14 - 4 = 10.
2let result = 20 - 6 - 4; BThe * runs before the +, so the answer is 16, not 36. It needs brackets: (10 + 2) * 3.
3Nested brackets: JavaScript works out the innermost brackets first, then works outwards. Clet total = (2 + (3 * 4)) * 5;
4Without brackets, * and / run before + and -, so only the last number is divided. DAdds a and b first because of the brackets, then divides the total by 2 to get the average.
5let avg = math + english / 2; Elet avg = a + b / 2;
6let answer = 10 + 2 * 3; // should be 36 FThere are no brackets, so only english is divided by 2 and then math is added. It should be (math + english) / 2.

Definitions

(a + b) / 2

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
let a = 6; let b = 10; let average = (a _ b) / 2;
2.
console.log((4 + 6) _ 2); // 5
3.
let result = 2 * ((3 + 5) - _); // 14
4.
let x = 20 / 5 _ 2; // 8
5.
let mark = (90 + 72 + 84) / _; // 82

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A let maths = 80;
B let english = 90;
C let avg = maths + english / 2;
D console.log(avg);
Question 2
A let a = 6;
B let b = 9, c = 12;
C let avg = a + b + c / 3;
D console.log(avg);
Question 3
A let c = 20;
B let f = c * 9 / (5 + 32);
C console.log(f);
Question 4
A let price = 12;
B let total = price + 3 * 4;
C console.log(total);
Question 5
A let x = (2 + (3 * 4) * 2;
B console.log(x);
C console.log(x - 10);

Answer Key

Order of operations with brackets
Section A: Quick Questions
Q1
B — 14
Q2
A — let avg = (a + b) / 2;
Q3
B — 11
Q4
A — 20
Q5
A — 12
Section B: Match the Pairs
Q1
let avg = (a + b) / 2; → Adds a and b first because of the brackets, then divides the total by 2 to get the average.
Q2
let result = 20 - 6 - 4; → Works left to right because - is on the same level, so it does 20 - 6 = 14 and then 14 - 4 = 10.
Q3
Nested brackets: JavaScript works out the innermost brackets first, then works outwards. → let total = (2 + (3 * 4)) * 5;
Q4
Without brackets, * and / run before + and -, so only the last number is divided. → let avg = a + b / 2;
Q5
let avg = math + english / 2; → There are no brackets, so only english is divided by 2 and then math is added. It should be (math + english) / 2.
Q6
let answer = 10 + 2 * 3; // should be 36 → The * runs before the +, so the answer is 16, not 36. It needs brackets: (10 + 2) * 3.
Section C: Definitions
Q1
(a + b) / 2 — Brackets run first, so a + b is added before dividing by 2. Then * and /, then + and -. Operators on the same level go left to right. Without brackets, only b is divided by 2.
Section D: Fill in the Blanks
Q1
let a = 6; let b = 10; let average = (a + b) / 2;
Q2
console.log((4 + 6) / 2); // 5
Q3
let result = 2 * ((3 + 5) - 1); // 14
Q4
let x = 20 / 5 * 2; // 8
Q5
let mark = (90 + 72 + 84) / 3; // 82
Section E: Spot the Error
Q1
C — Without brackets, only english is divided by 2 because / runs before +. It should be (maths + english) / 2 so the marks are added first.
Q2
C — Division happens before addition, so only c is divided by 3. Brackets are needed around a + b + c so the sum is divided: (a + b + c) / 3.
Q3
B — The brackets make JavaScript add 5 + 32 first, then divide by 37. The formula needs c * 9 / 5 + 32, with no brackets, so the multiply and divide run before the add.
Q4
B — Without brackets, 3 * 4 is worked out first, giving 24 instead of 60. Brackets are needed so price + 3 is added before multiplying: (price + 3) * 4.
Q5
A — The brackets are not paired. The outer opening bracket is never closed. It should be (2 + (3 * 4)) * 2, so the inner brackets run first, then the outer ones.