You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.1 KiB
35 lines
1.1 KiB
const PI = Math.PI
|
|
console.log(PI) // 3.141592653589793
|
|
console.log(Math.round(PI)) // 3; to round values to the nearest number
|
|
console.log(Math.round(9.81)) // 10
|
|
console.log(Math.floor(PI)) // 3; rounding down
|
|
console.log(Math.ceil(PI)) // 4; rounding up
|
|
console.log(Math.min(-5, 3, 20, 4, 5, 10)) // -5, returns the minimum value
|
|
console.log(Math.max(-5, 3, 20, 4, 5, 10)) // 20, returns the maximum value
|
|
|
|
const randNum = Math.random() // creates random number between 0 to 0.999999
|
|
console.log(randNum)
|
|
// Let create random number between 0 to 10
|
|
const num = Math.floor(Math.random() * 11) // creates random number between 0 and 10
|
|
console.log(num)
|
|
|
|
//Absolute value
|
|
console.log(Math.abs(-10)) //10
|
|
//Square root
|
|
console.log(Math.sqrt(100)) // 10
|
|
console.log(Math.sqrt(2)) //1.4142135623730951
|
|
// Power
|
|
console.log(Math.pow(3, 2)) // 9
|
|
console.log(Math.E) // 2.718
|
|
|
|
// Logarithm
|
|
//Returns the natural logarithm of base E of x, Math.log(x)
|
|
console.log(Math.log(2)) // 0.6931471805599453
|
|
console.log(Math.log(10)) // 2.302585092994046
|
|
|
|
// Trigonometry
|
|
console.log(Math.sin(0))
|
|
console.log(Math.sin(60))
|
|
console.log(Math.cos(0))
|
|
console.log(Math.cos(60))
|