Standard Javascript Objects

The Math Object

🙋 Need help? Ask an expert now!

The Math object provides some mathematical functions such as rounding, exponents, sine, cosine, tangent, etc. These functions may or may not benefit you depending on the program you are writing and the intended use. Even though, the sample code below uses a concepts (such as the for loop) you haven't learnt yet, try to understand why the Math object is used and how it could benefit your code in the future.

The functions Math.random() and Math.floor are shown above in the sample code to illustrate a random number generator for numbers in between 1 and 100. There are many other functions you can use in the Math Object that are documented online at your disposal. Make sure you always call the function using Math.someMethod(), not just someMethod(). You will not be able to use the functions in the Math Object without referencing it in your code. Play around with the random number generator below and try to print random numbers in between 50 to 100 instead of 1 to 100.

Edit Me on GitHub!

Application Question

What does the function Math.random() return?