我制作了一个简单的随机数生成器脚本,但它不起作用。我已经在一个html文档中打开了这个,我知道我没有犯错,因为我已经使用HTML一段时间了。我仍会表明,如果有人需要它。我不知道这有什么问题,但变量randomNumber不会打印到屏幕上。有什么想法吗?
var randomNumber = math.Random();
if (randomNumber <= 0.09)
{
randomNumber = 1;
}
else if (randomNumber >= 0.1 && randomNumber <= 0.19)
{
randomNumber = 2;
}
else if (randomNumber >= 0.2 && randomNumber <= 0.29)
{
randomNumber = 3;
}
else if (randomNumber >= 0.3 && randomNumber <= 0.39)
{
randomNumber = 4;
}
else if (randomNumber >= 0.4 && randomNumber <= 0.49)
{
randomNumber = 5;
}
else if (randomNumber >= 0.5 && randomNumber <= 0.59)
{
randomNumber = 6;
}
else if (randomNumber >= 0.6 && randomNumber <= 0.69)
{
randomNumber = 6;
}
else if (randomNumber >= 0.7 && randomNumber <= 0.79)
{
randomNumber = 7;
}
else if (randomNumber >= 0.8 && randomNumber <= 0.89)
{
randomNumber = 8;
}
else if (randomNumber >= 0.9)
{
randomNumber = 9;
}
else if (rn2 <= 0.09)
{
randomNumber = 10;
}
// rn2's purpose is do dictate whether the variable randomNumber will be 10
var rn2 = math.Random();
document.write("The number is " + randomNumber + ".");