UX Design and Development course

Fun with operators

Create some vars using some simple operators

var simpleMath = 10 / 3;
var modMath = 10 % 3;

Output the full value

console.log(simpleMath);

Output the remainder or mod

console.log(modMath);

Output the nearest integer

console.log(Math.round(simpleMath));

Output the rounded up integer

console.log(Math.ceil(simpleMath));

Output the rounded down integer

console.log(Math.floor(simpleMath));

Assignment operators

This is a basic single operator assignment

var houseNumber = 1944;
console.log(houseNumber);

Assignment operators can also do math

var valueOne = 1020;
var valueTwo = 10;

Redefine a variable using an operator

options are +=, -=, *=, /=

valueOne -= valueTwo;

console.log(valueOne);

Fun with code

JS Bin