Menu
Coddy logo textTech

Arithmetic Shortcuts

Part of the Fundamentals section of Coddy's JavaScript journey — lesson 14 of 77.

JavaScript created a cool shortcut for self-arithmetic operations.

For example, instead of writing:

let a = 5
a = a + 3 // a holds 8

We can simplify it by writing +=:

let a = 5
a += 3 // a holds 8

The += is adding to a itself the value 3

This operation is valid for all arithmetic operations:

OperatorShortcut
++=
--=
**=
//=
%%=
challenge icon

Challenge

Beginner

You are given a code with initialization of count. (Don't delete this line!)

Your task is to add the following operations, in this order:

  1. Add 4 to count
  2. Multiply count by 2
  3. Subtract 1 from count

Use the arithmetic shortcuts to do so!

Cheat sheet

JavaScript provides shortcut operators for self-arithmetic operations:

OperatorShortcut
++=
--=
**=
//=
%%=

Instead of writing:

let a = 5
a = a + 3 // a holds 8

You can use the shortcut:

let a = 5
a += 3 // a holds 8

Try it yourself

// Type your code below
let count = 0

// Don't change the line below
console.log(`count = ${count}`)
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals