Maths in Javascript

Since this course is from basic to advanced, we are going to discuss very basic mathematical operations . In case it is too trivial for you please skip this section.

console.log(5+7); //addition
console.log(7-4); //subtraction
console.log(5*10); // multiplication
console.log(15/3); // divison
console.log(16/3); // divison
console.log(103%10); // modulo

Output:

Different math object and methods

console.log(Math.PI);
console.log(Math.E);
console.log(Math.round(6.3));
console.log(Math.round(6.7));
console.log(Math.ceil(8.1));
console.log(Math.floor(8.1));
console.log(Math.sqrt(16));
console.log(Math.sqrt(17));
console.log(Math.abs(-11));

Output:

 

console.log(Math.PI);
console.log(Math.E);
console.log(Math.round(6.3));
console.log(Math.round(6.7));
console.log(Math.ceil(8.1));
console.log(Math.floor(8.1));
console.log(Math.sqrt(16));
console.log(Math.sqrt(17));
console.log(Math.abs(-11));
console.log(Math.pow(2,5));
console.log(Math.min(1,-3,5,7));
console.log(Math.max(1,-3,5,7));
console.log(Math.random());
console.log(Math.floor(Math.random()*50 + 1));

Output: