Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using math object 1

Status
Not open for further replies.

tnbrwneyez

Programmer
Oct 2, 2004
19
US
I need to take the following code and create a variable named num and assign its value a random integer between 0 and 9> I need to use the Math object's round ()and random () methods in tandem to accomplish this task. The random number must be multiplied by 9. I need to use the round () method to round that number to the nearest integer.

<SCRIPT LANGUAGE="JavaScript">
<!--

// Make sure these quotes don't wrap in your file

var quotes = new Array()
quotes[0] = "Every time history repeats itself the price goes up.<BR><small><i>- Anonymous</i></small>"
quotes[1] = "The moment you think you understand a great work of art, it's dead for you.<BR><small><i>- Robert Wilson</small></i>"
quotes[2] = "To love one person with a private love is poor and miserable; to love all is glorious.<BR><small><i>- Thomas Traherne</small></i>"
quotes[3] = "Every violation of truth is not only a sort of suicide in the liar, but is a stab at the health of human society.<BR><small><i>- Ralph Waldo Emerson</i></small>"
quotes[4] = "Man is to be found in reason, God in the passions.<BR><small><i>- G. C. Lichtenberg</i></small>"
quotes[5] = "Great innovations should not be forced on slender majorities.<BR><small><i>- Thomas Jefferson</i></small>"
quotes[6] = "In this world nothing can be said to be certain, except death and taxes.<BR><small><i>- Benjamin Franklin</i></small>"
quotes[7] = "Nine-tenths of wisdom consists in being wise in time.<BR><small><i>- Theodore Roosevelt</i></small>"
quotes[8] = "We have no more right to consume happiness without producing it than to consume wealth without producing it.<BR><small><i>- George Bernard Shaw</i></small>"
quotes[9] = "So little done, so much to do.<BR><small><i>- Cecil Rhodes</i></small>"

// Use Math object






// -->
</SCRIPT>

I appreciate any help!!

Thanks
 
You seem to know exactly how to do this already. In case you don't, call functions of the Math object throught Math.functionName().

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
What do I need to put where? Sorry, but JavaScript is not by strong point.

Thanks
 
var num = Math.floor(Math.random()*9)

Math.floor rounds down, Math.round() rouns down for <5, up for >=5.

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top