We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Numbers in JS

In Python, numbers without a decimal part are called Integers (int) and fractions are Floats (float). Contrast this to JavaScript where all numbers are just a Number type.

You're already familiar with the number type. Numbers aren't surrounded by quotes when created, but they can contain decimal parts and negative signs.

let x = 2; // this is a number
x = 5.69; // this is also a number
x = -5.42; // yup, still a number

You can do arithmetic as you'd expect:

let sum = 2 + 3 + 7; // 12
let difference = 5.3 - 2.1; // 3.2
let product = 2 * 3; // 6
let quotient = 6 / 2; // 3

Assignment

Textio tracks the number of messages sent for different types of notifications. Between the comments, create a:

  • totalMessagesSent variable that contains the total number of messages sent.
  • averageMessagesSent variable that contains the average number of messages sent across all types.