# Math object

  • The Math object is a built-in object with mathematical constants (properties) and methods
    • Unlike many other built-in objects, Math is a static object which has no constructor, so every property/method starts with Math.

# Frequently used (static) properties

property description
Math.PI (opens new window) a constant that approximately equals 3.14159

# Frequently used (static) methods

methode description
Math.ceil(<x>) (opens new window) round <x> up to the nearest integer
Math.floor(<x>) (opens new window) round <x> down to the nearest integer
Math.round(<x>) (opens new window) round <x> to the nearest integer (>= .5 round up, < .5 round down)
Math.random() (opens new window) generate a random number between 0 (included) and 1 (excluded)
Math.abs(<x>) (opens new window) returns the absolute value of <x>

# Examples

# Cylinder volume

  • Open es6/math/cylinder.html and es6/math/cylinder.js
  • Calculate the volume of a cylinder (and round it to 2 decimal points)

# Roll the dice

  • Open es6/math/dice.html and es6/math/dice.js

# Exercises

  • Open exercises/index.html and make the exercises under the tab ES6 > Math object
Last Updated: 4/22/2021, 10:20:29 PM