edit-article
Home
Up
Delete
Article Name:
Article Description:
Math - an overview of the native JavaScript language object Math
Chapter ID/Name:
Status:
Write
Writing
Written
Add Photo:
Owner ID:
Content:
use HTML
Edit Content
<h1 style="text-align: center;"> Math Object</h1> <h2>[WHAT]</h2> <ol> <li>[] the Math object is used to perform a number of mathematical functions.</li> </ol> <h2>[WHY]</h2> <ol> <li>[] to perform standard math operations on numbers without having to write </li> </ol> <h2>[WHERE]</h2> <ol> <li>[] you need to perform 'standard' mathematical functions on a given number, such as sqrt, log, sin,</li> </ol> <h2>[WHEN]</h2> <ol> <li>[] </li> </ol> <h2>[EXAMPLE]</h2> <ol> <li><strong>[] generating a random number<br /></strong></li> </ol> <div>var randomNum = Math.random() // returns a value between 0 and 1</div> <div><ol> <li><strong>[] generating a random number between 1 and 100</strong><strong></strong><br /><strong></strong></li> </ol> <div> <div>getRandomBetween(min,max){</div> <div> return Math.random() * (max - min) + min;</div> <div>}</div> <div>console.log(getRandomNumberBetween(1,100); // this returns a float, so will get 51.78</div> <div><ol> <li><strong>[] would you then use Math.round() or Math.floor to return an integer value ?</strong></li> </ol>round would return 52, floor would return 51</div> </div> </div> <ol> <li><strong>[] get the largest number in a given set of numbers<br /></strong></li> </ol> <div>var largest = Math.max(17,9,23,44);</div> <h2>[HOW-TO]</h2> <ol> <li>[]</li> </ol> <h2>[REFERENCE]</h2> <ol> <li><span class="crayon-sy">[]</span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math" target="_blank"> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math</a> </li> </ol>