JavaScript: Numbers

Table of Contents

Types of numbers

var a = 3 + 3;
var a = 3 - 3;
var a = 3 * 3;
var a = 3 / 3;
var a = 9 % 6; // Gives the reaming 3

Challenge

Dog age to human age: Ask the age of the dog and prompt the age of a human.

humanAge = (dogAge -2) * 4 + 21
var dogAge = prompt("What is your dog's age?");
alert("Your dog's human age is " + ((dogAge -2) * 4 + 21));

Increment and Decrement

Increment: The increment (++) operator increments (adds one to) its operand and returns the value before or after the increment, depending on where the operator is placed.

Decrement: The decrement (--) operator decrements (subtracts one from) its operand and returns the value before or after the decrement, depending on where the operator is placed.

var x = 5;
x = x + 1; // 6
x++; // 6
x--; // 4
x += 2; // 7
x +- 2 // 3
var y = 3;
x += y; //8