forked from Pankaj-Str/JavaScript-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumbers.js
More file actions
57 lines (42 loc) · 1.08 KB
/
numbers.js
File metadata and controls
57 lines (42 loc) · 1.08 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// number in JS
// random number
let randomNumber = Math.random();
console.log(randomNumber); // 0.123456789
// random number between 0 and 100
let randomNumberBetween0and100 = Math.floor(Math.random() * 100);
console.log(randomNumberBetween0and100); // 45
// square root
let squareRoot = Math.sqrt(16);
console.log(squareRoot); // 4
// absolute value
let absoluteValue = Math.abs(-10);
console.log(absoluteValue); // 10
// round
let roundNumber = Math.round(4.5);
console.log(roundNumber); // 5
// round up
let roundUp = Math.ceil(4.2);
console.log(roundUp); // 5
// round down
let roundDown = Math.floor(4.8);
console.log(roundDown); // 4
// max
let maxNumber = Math.max(1, 2, 3, 4, 5);
console.log(maxNumber); // 5
// min
let minNumber = Math.min(1, 2, 3, 4, 5);
console.log(minNumber); // 1
// power
let power = Math.pow(2, 3);
console.log(power); // 8
// pi
let pi = Math.PI;
console.log(pi); // 3.141592653589793
// e
let e = Math.E;
console.log(e); // 2.718281828459045
// log
let log = Math.log(10);
// log base 10
let logBase10 = Math.log10(100);
console.log(logBase10); // 2