-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmath-functions.js
More file actions
41 lines (21 loc) · 1.34 KB
/
math-functions.js
File metadata and controls
41 lines (21 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//? jAVASCRIPT Math Functions
//! 9 Comman Js Math Function
//* The math function helps us to perform methematical operations on numbers
// 1. Math.random() : this method return a random number between 0 and 1.
console.log(Math.random()); // Output: 0.9935936579868072
// 2. Math.pow() : this method takes two parameters like Math.pow(x,y) and returns a value of x to the power y.
console.log(Math.pow(2, 5)); // 32
// 3. Math.sqrt() : this method returns the square root of a given number
console.log(Math.sqrt(16)); // 4
// 4. Math.floor() : This method returns a value of given number down to its nearest number.
console.log(Math.floor(10.5)); // 10
// 5. Math.ceil() : this method returns a value of given number up to its nearest number
console.log(Math.ceil(10.5)); // 11
// 6 Math.trunc() : it returns only the integer part of the given number by removing fractional units.
console.log(Math.trunc(10.5)); // 10
// 7 Math.abs() : this method returns the absolute value i.e Positive value of a given number.
console.log(Math.abs(-10.5)); // 10.5
// 8 Math.min() : this methods return the lowest value from a provided list of numeric values.
console.log(Math.min(2, 3, 4, 5, 6, 7, 7, 8, 1, 0)); // 0
// 9 Math.max() : this methods return the highest value from a provided lis of numeric values.
console.log(Math.max(2, 3, 4, 5, 6, 7, 8, 9, 1, 0)); // 9