1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "UTF-8">5 <title>JS's Math Object</title>6 <Scripttype= "Text/javascript">7 //the Math object is a static method that you can use without instantiating an object.8 varNum= 10.5;9 document.write ("Initial value:" +num);Ten //ceil () method, rounding a number One document.write ("<br/> Rounding up the Ceil () method:" +Math.ceil (num)); A //Floor () method, rounding down a number - document.write ("<br/> Rounds down the Floor () method:" +Math.floor (num)); - //round () method, rounding a number the document.write ("<br/> Rounding Round () method:" +Math.Round (num)); - //Random (), gets the stochastic number (0.0-1.0 pseudo-random number). Get a random number of 0-9 - document.write ("<br/> Random number ():" +Math.floor (Math.random ()* Ten)); - functionGetrandom () { + document.getElementById ('Mark'). InnerHTML= "Random Number:" +Math.floor (Math.random ()* Ten); - SetTimeout ('getrandom ()', $); + } A </Script> at </Head> - <Bodyonload= "Getrandom ()"> - <PID= "Mark">Random number</P> - </Body> - </HTML>
The Math object for JavaScript Foundation 14--js