📖 Scenario: You are helping a small shop calculate prices and discounts for their products. You will use arithmetic operators to do simple math calculations.
🎯 Goal: Build a small program that calculates the total price of items, applies a discount, and shows the final amount to pay.
📋 What You'll Learn
Create variables with exact values for product prices
Create a variable for discount percentage
Calculate total price and discounted price using arithmetic operators
Print the final price after discount
💡 Why This Matters
🌍 Real World
Calculating prices and discounts is common in shops and online stores to show customers how much they pay.
💼 Career
Understanding arithmetic operators is essential for any programming job that involves calculations, such as web development, data analysis, or game programming.
Progress0 / 4 steps
1
Create product price variables
Create three variables called price1, price2, and price3 with values 10, 20, and 30 respectively.
Javascript
Hint
Use let to create variables and assign the exact numbers.
2
Create discount percentage variable
Create a variable called discountPercent and set it to 10 to represent a 10% discount.
Javascript
Hint
Remember to use let and assign the number 10.
3
Calculate total and discounted price
Create a variable called totalPrice that adds price1, price2, and price3. Then create a variable called discountedPrice that subtracts the discount amount from totalPrice. Use arithmetic operators to calculate the discount amount as totalPrice * discountPercent / 100.
Javascript
Hint
Use + to add prices and -, *, and / to calculate the discount.
4
Print the final discounted price
Write a console.log statement to print the text "Final price after discount: " followed by the value of discountedPrice.
Javascript
Hint
Use console.log and string concatenation with +.
Practice
(1/5)
1. Which arithmetic operator in JavaScript is used to find the remainder of a division?
easy
A. %
B. /
C. **
D. *
Solution
Step 1: Understand the remainder operator
The operator % returns the remainder after division of two numbers.
Step 2: Compare with other operators
/ is division, ** is power, and * is multiplication, so they don't give remainder.
Final Answer:
% -> Option A
Quick Check:
Remainder operator = % [OK]
Hint: Remainder operator looks like a percent sign % [OK]
Common Mistakes:
Confusing division / with remainder %
Using * or ** instead of %
Thinking + or - can give remainder
2. Which of the following is the correct syntax to calculate 5 to the power of 3 in JavaScript?
easy
A. 5 ** 3
B. 5 ^^ 3
C. 5 ^ 3
D. pow(5, 3)
Solution
Step 1: Identify the power operator in JavaScript
JavaScript uses ** to calculate powers, like 5 ** 3 means 5 to the power 3.
Step 2: Check other options for correctness
^ is bitwise XOR, ^^ is invalid syntax, and pow() is not a built-in function in JavaScript.
Final Answer:
5 ** 3 -> Option A
Quick Check:
Power operator = ** [OK]
Hint: Use ** for power, not ^ or pow() [OK]
Common Mistakes:
Using ^ instead of ** for power
Trying to use pow() like in other languages
Typing invalid operators like ^^
3. What will be the output of the following code?
console.log(10 % 4);
medium
A. 6
B. 0
C. 2
D. 4
Solution
Step 1: Calculate 10 divided by 4
10 divided by 4 is 2 with a remainder of 2.
Step 2: Understand the % operator
The % operator returns the remainder, so 10 % 4 equals 2.
Final Answer:
2 -> Option C
Quick Check:
10 % 4 = 2 [OK]
Hint: Remainder is what's left after division [OK]
Common Mistakes:
Confusing remainder with quotient
Thinking % does division
Choosing 0 or 4 as remainder incorrectly
4. Find the error in this code snippet:
let result = 5 **;
console.log(result);
medium
A. console.log syntax error
B. Using wrong operator for power
C. Variable name 'result' is invalid
D. Missing right operand for ** operator
Solution
Step 1: Check the power operator usage
The power operator ** needs two operands, like 5 ** 2. Here, the right operand is missing.
Step 2: Verify other parts of the code
The variable name and console.log syntax are correct, so no errors there.
Final Answer:
Missing right operand for ** operator -> Option D
Quick Check:
Power operator needs two numbers [OK]
Hint: Power operator needs number on both sides [OK]
Common Mistakes:
Leaving out the second number after **
Thinking variable names cause error here
Assuming console.log is wrong
5. You want to split 100 candies equally among 6 kids and find how many candies remain undistributed. Which expression gives the number of leftover candies?
hard
A. 100 / 6
B. 100 % 6
C. 100 - 6
D. 100 ** 6
Solution
Step 1: Understand the problem
We want the leftover candies after dividing 100 by 6, which means the remainder.
Step 2: Choose the correct operator
The remainder operator % gives the leftover amount, so 100 % 6 is correct.
Final Answer:
100 % 6 -> Option B
Quick Check:
Leftover = total % number [OK]
Hint: Use % to find leftovers after division [OK]
Common Mistakes:
Using / which gives quotient, not remainder
Subtracting numbers directly instead of remainder
Using power operator mistakenly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.