2.5 Basic Math Lesson Slide Deck
 
JavaScript Math Operators - Lesson Slides

๐Ÿš€ JavaScript Math Operators

Master Arithmetic in Code!

Grade 8 JavaScript Programming

๐ŸŽฏ Today's Objective

Students will use arithmetic operators to write JavaScript programs that solve problems with 80% accuracy.

By the end of class, you'll write programs that calculate costs, split bills, and animate graphics!

๐Ÿ• Warm-Up: The Mystery Restaurant Bill

Four friends went to dinner. The bill was $68.

They want to split it equally, BUT one friend has a $10 gift card.

How much does each person actually pay?

Think: What calculations do you need? In what order?

๐ŸŽฏ The Programming Pattern

1๏ธโƒฃ

GET

Collect information from the user using readInt() or readFloat()

2๏ธโƒฃ

CALCULATE

Use operators (+, โˆ’, *, /, %) to solve the problem

3๏ธโƒฃ

DISPLAY

Show results using console.log()

Every program you write will follow this pattern!

๐Ÿ”ข JavaScript Math Operators

+
Addition
Adds two numbers
5 + 3 = 8
โˆ’
Subtraction
Subtracts numbers
10 - 4 = 6
*
Multiplication
Multiplies numbers
6 * 7 = 42
/
Division
Divides numbers
20 / 4 = 5

๐Ÿ”„ The Mysterious Modulus Operator

What is % (Modulus)?

It finds the REMAINDER after division

17 % 5 = 2

Because 17 รท 5 = 3 remainder 2

๐Ÿ’ก Use for: Checking odd/even, finding leftovers, time conversion

๐Ÿ’ป Live Demo: Pizza Program

Problem: Calculate total cost for pizzas at $12 each

// STEP 1: GET information let pricePerPizza = 12; let quantity = readInt("How many pizzas? "); // STEP 2: CALCULATE the total let total = pricePerPizza * quantity; // STEP 3: DISPLAY the result console.log("Your total is $" + total);

โš ๏ธ Common Mistake: Wrong Operator!

โŒ WRONG

12 + 5 = 17

Using + gives you the wrong answer!

5 pizzas should NOT cost $17!

โœ… CORRECT

12 * 5 = 60

Using * multiplies correctly!

5 pizzas at $12 each = $60

Choose the RIGHT operator or your program breaks!

๐ŸŽฏ How to Choose the Right Operator

  • Combining amounts? โ†’ Use + (total savings, combined scores)
  • Finding what's left? โ†’ Use โˆ’ (change, discounts)
  • Repeated items? โ†’ Use * (price ร— quantity)
  • Splitting equally? โ†’ Use / (split bills, averages)
  • Finding remainder? โ†’ Use % (odd/even, leftovers)

๐ŸŒ Quia Interactive Practice

Before we code in CodeHS, let's see these operators in action!

https://www.quia.com/pages/jessica559si/javacriptmath

Watch how changing operators changes results completely

๐Ÿ’ฐ CodeHS 2.5.3: Bookstore

Your Task:

Write a program for a bookstore that:

  • Asks how many books the customer wants
  • Calculates the total cost (books are $15 each)
  • Displays the total

Example: 3 books should cost $45

๐Ÿฆ CodeHS 2.5.4: Flying Pigeon

Animation = Math Repeated Quickly!

To move something across the screen, you change its position using math:

// Move right: ADD to x position pigeon.x = pigeon.x + 3; // Move up: SUBTRACT from y position pigeon.y = pigeon.y - 1;

Every 0.05 seconds, the computer recalculates position!

๐Ÿ› Debug Challenge: Find the Bugs!

// Movie ticket program - has 3 bugs! let ticketPrice = 10 let numTickets = readInt("How many tickets? "); let popcorn = 6; let total = ticketPrice + numTickets + popcorn; console.log("Your total is: " total); let change = 50 / total; console.log("Your change from $50 is: $" + change);

Can you find all 3 bugs? Think about operators and syntax!

๐Ÿงฉ Practice Problems

Problem 1: Gaming Console ๐ŸŽฎ

Console costs $300. You save $15/week. Calculate weeks needed.

Problem 2: Road Trip ๐Ÿš—

Car gets 28 mpg. Gas costs $3.50/gallon. Calculate cost for 280-mile trip.

๐Ÿ’ก Pro Tips for Success!

  • โœ… Choose the RIGHT operator - Using + instead of * breaks everything!
  • โœ… Order matters - Use ( ) to control calculations
  • โœ… Test your code - Try the example numbers first
  • โœ… Add comments - Explain what each step does
  • โœ… Variable names matter - Use totalCost not x

๐Ÿ’ญ Reflection

When would using the WRONG operator completely break your program?

Give a specific example from today.

Think-Write-Share with a partner

๐Ÿ  Homework Choice Board

Pick 2 of 4 activities:

  • Bill Splitter Pro ๐Ÿ’ต - Split bills with tip options (15%, 18%, 20%)
  • Grade Calculator ๐Ÿ“Š - Points earned รท points possible ร— 100
  • Time Converter โฐ - Minutes to hours and minutes using / and %
  • Profit Calculator ๐Ÿ“ˆ - Revenue โˆ’ costs, profit margin percentage

BONUS: Complete Quia interactive activities for extra credit!

๐ŸŽ‰ Great Job Today!

You learned:

  • The 5 arithmetic operators
  • The GET โ†’ CALCULATE โ†’ DISPLAY pattern
  • How to choose the right operator
  • How to debug code
  • How animation uses math!

Keep coding! ๐Ÿš€

1 / 18
Last updated  2026/01/19 02:17:30 PSTHits  27