|
| 1 | +const PI = Math.PI |
| 2 | +console.log(PI) // 3.141592653589793 |
| 3 | +console.log(Math.round(PI)) // 3; to round values to the nearest number |
| 4 | +console.log(Math.round(9.81)) // 10 |
| 5 | +console.log(Math.floor(PI)) // 3; rounding down |
| 6 | +console.log(Math.ceil(PI)) // 4; rounding up |
| 7 | +console.log(Math.min(-5, 3, 20, 4, 5, 10)) // -5, returns the minimum value |
| 8 | +console.log(Math.max(-5, 3, 20, 4, 5, 10)) // 20, returns the maximum value |
| 9 | + |
| 10 | +const randNum = Math.random() // creates random number between 0 to 0.999999 |
| 11 | +console.log(randNum) |
| 12 | +// Let create random number between 0 to 10 |
| 13 | +const num = Math.floor(Math.random() * 11) // creates random number between 0 and 10 |
| 14 | +console.log(num) |
| 15 | + |
| 16 | +//Absolute value |
| 17 | +console.log(Math.abs(-10)) //10 |
| 18 | +//Square root |
| 19 | +console.log(Math.sqrt(100)) // 10 |
| 20 | +console.log(Math.sqrt(2)) //1.4142135623730951 |
| 21 | +// Power |
| 22 | +console.log(Math.pow(3, 2)) // 9 |
| 23 | +console.log(Math.E) // 2.718 |
| 24 | + |
| 25 | +// Logarithm |
| 26 | +//Returns the natural logarithm of base E of x, Math.log(x) |
| 27 | +console.log(Math.log(2)) // 0.6931471805599453 |
| 28 | +console.log(Math.log(10)) // 2.302585092994046 |
| 29 | + |
| 30 | +// Trigonometry |
| 31 | +console.log(Math.sin(0)) |
| 32 | +console.log(Math.sin(60)) |
| 33 | +console.log(Math.cos(0)) |
| 34 | +console.log(Math.cos(60)) |
0 commit comments