Hi,
I am a newbie to JavaScript. I have created the following script just to generate a random number and perform a few tasks on it:
<html>
<head>
<title>Random Generator</title>
<script LANGUAGE = "JavaScript">
//create a variable 'rand1' to get a random number between 0.0 to 1.0
var rand1 = Math.random();
//create a variable 'rand2' which gets the random value rand1 and and makes it between 0.0 and 10.0
var rand2 = rand1 * 10;
//create a variable 'rand3' which gets the value of rand2 and rounds it to make in between 1 and 10.
var rand3 = Math.ceil(rand3);
//add each part to a string
var str = "Random float [rand1]: " + rand1 + "\n";
str += "Sepcify range [rand2]: " + rand2 + "\n";
str += "Random Integer [rand3]: " + rand3 + "\n";
//display the string
alert(str);
</script>
</head>
<body>
Random number generator
</body>
</html>
When I recieve the output, the last line reads:
Random integer [rand3]: NaN
After checking google I found that NaN stands for Not a number. Can anyone see why I get this?
Thanks in advance
Rob
I am a newbie to JavaScript. I have created the following script just to generate a random number and perform a few tasks on it:
<html>
<head>
<title>Random Generator</title>
<script LANGUAGE = "JavaScript">
//create a variable 'rand1' to get a random number between 0.0 to 1.0
var rand1 = Math.random();
//create a variable 'rand2' which gets the random value rand1 and and makes it between 0.0 and 10.0
var rand2 = rand1 * 10;
//create a variable 'rand3' which gets the value of rand2 and rounds it to make in between 1 and 10.
var rand3 = Math.ceil(rand3);
//add each part to a string
var str = "Random float [rand1]: " + rand1 + "\n";
str += "Sepcify range [rand2]: " + rand2 + "\n";
str += "Random Integer [rand3]: " + rand3 + "\n";
//display the string
alert(str);
</script>
</head>
<body>
Random number generator
</body>
</html>
When I recieve the output, the last line reads:
Random integer [rand3]: NaN
After checking google I found that NaN stands for Not a number. Can anyone see why I get this?
Thanks in advance
Rob