Practical Arithmetic Patterns
What you'll learn: How to apply JavaScript's arithmetic operators to solve everyday calculation tasks like totals, averages, percentages, and common formulas.
Putting Arithmetic to Work
You've learned all the individual operators—now it's time to combine them into practical patterns you'll use constantly in real programs. These patterns solve common problems like calculating shopping cart totals, grade averages, tax amounts, and more.
Common Real-World Patterns
Calculating Totals
let item1 = 29.99;
let item2 = 15.50;
let item3 = 42.00;
let total = item1 + item2 + item3; // 87.49
Computing Averages
let score1 = 85;
let score2 = 92;
let score3 = 78;
let average = (score1 + score2 + score3) / 3; // 85
Finding Percentages
let price = 200;
let taxRate = 0.08; // 8%
let taxAmount = price * taxRate; // 16
let totalWithTax = price + taxAmount; // 216
Percentage of a Value
let total = 500;
let completed = 375;
let percentComplete = (completed / total) * 100; // 75
Temperature Conversion
let celsius = 25;
let fahrenheit = (celsius * 9 / 5) + 32; // 77
Discount Calculations
let originalPrice = 100;
let discountPercent = 20;
let discountAmount = originalPrice * (discountPercent / 100); // 20
let finalPrice = originalPrice - discountAmount; // 80
Think Step-by-Step
Break complex calculations into smaller steps using intermediate variables. This makes your code readable and debuggable. Remember to use parentheses to control operation order when needed.
Key Takeaway: Real-world arithmetic patterns combine basic operators into formulas for totals, averages, percentages, and conversions—think of them as reusable calculation recipes you'll apply throughout your programs.