Introduction To Programming
10-152-310

Learning Plan 3 : Math and Operators

Multiplicative Operators

  • The asterisk (*) is used for multiplication
  • The forward slash (/) is used for division
  • The percent sign (%) is the modulo operator.

Multiplying

You can multiply numbers and number variables. When you multiply a number and a string the string will be converted to a number by JavaScript. Even when you multiply a string by a string JavaScript will convert the strings to numbers, if it can.

        
        

        

Dividing

You can divide numbers and variables. When you divide a number and a string the string will be converted to a number by JavaScript. Even when you divide a string by a string JavaScript will convert the strings to numbers, if it can.

        
        

        

Modulo Operator

The modulo operator is very simple. Remember back in elementary school when you learned to do division manually? They called it "long division" in my era. The modulo operator just gives you the remainder when you divide two numbers.

Modulo Example

Here's how we code it in JavaScript.

        
        

        

And here's more examples.