In addition to the mathematical constants that can be accessed from the Math object there are also several methods available.

The following example uses the round() method of the Math object to round a number to the nearest integer:

 document.write(Math.round(4.7));

The code above will result in the following output:
5

The following example uses the random() method of the Math object to return a random number between 0 and 1:

 document.write(Math.random());

The code above can result in the following output:
0.6936874867631697 

The following example uses the floor() and random() methods of the Math object to return a random number between 0 and 10:

 document.write(Math.floor(Math.random()*11));

The code above can result in the following output:
0


This entry was posted on 11:32 PM and is filed under . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

1 comments:

    Donttrustgal said...

    Hiii.... U did a gr8 job.....
    thank you so much.....

    But i have a prob......
    in blog post how can i use javascript.....???

    Javascript work in gadget but not in post... so please tell me how can i use javascript in blog post

  1. ... on February 12, 2010 at 1:34 AM