English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

//Here is the code pertaining to the problem...

var mRN = function getRandom()
{
return Math.random()*10
};
/*Code works just fine, when I call on it it returns a random
number.

Now my question, mRN will acquire a new random number
for every time it is called upon.. here is the next part of the code:
*/

document.write(mRN());
document.write("

Rounding:
");
document.write(Math.round(mRN()));

*/How do I make mRN return the same value to line 1 and 3 above so I can put what the number in line 1 is when rounded?

Thanks
*/

2007-04-25 09:24:51 · 2 answers · asked by Simba 4 in Computers & Internet Programming & Design

2 answers

var mRN = function() {return Math.random()*10}

var randomNumber = mRN()

document.write(randomNumber)
document.write("

Rounding: document.write(Math.round(randomNumber))

2007-04-25 09:57:30 · answer #1 · answered by jake cigar™ is retired 7 · 1 0

The answer is that you don't.
What you do is assign the return value of mRN() to a variable
var randNumber=mRN();
Now do what you want with the variable and not the function.

This is called programming!

2007-04-25 16:45:40 · answer #2 · answered by AnalProgrammer 7 · 0 0

fedest.com, questions and answers