想把 i<= 后面的写个函数。老师出错啊。
<script language="javascript" type="text/javascript">
var d = new Date()
var time = d.getHours()
if (time<8)
{
total = 0
for(i=100;i<=200;i++)
{num=Math.random();
total +=num}
average = total
average = Math.round(average)
document.write("<h1>"+average+"</h1>")
}
else if (time>=8 && time<18)
{
total = 0
for(i=100;i<=600;i++)
{num=Math.random();
total +=num}
average = total
average = Math.round(average)
document.write("<h1>"+average+"</h1>")
}
else if (time>=18 && time<21)
{
total = 0
for(i=100;i<=400;i++)
{num=Math.random();
total +=num}
average = total
average = Math.round(average)
document.write("<h1>"+average+"</h1>")
}
else
{
total = 0
for(i=100;i<=300;i++)
{num=Math.random();
total +=num}
average = total
average = Math.round(average)
document.write("<h1>"+average+"</h1>")
}
</script>
------解决方案--------------------
LZ你到底想干嘛?这些大括号需要么?
<script language="javascript" type="text/javascript">
var d = new Date()
var time = d.getHours()
if (time<8)
{
total = 0
for(i=100;i<=200;i++)
{num=Math.random();
total +=num}
average = total
average = Math.round(average)
document.write("<h1>"+average+"</h1>")
}
else if (time>=8 && time<18)
{
total = 0
for(i=100;i<=600;i++)
{num=Math.random();
total +=num}
average = total
average = Math.round(average)
document.write("<h1>"+average+"</h1>")
}
else if (time>=18 && time<21)
{
total = 0
for(i=100;i<=400;i++)
{num=Math.random();
total +=num}
average = total
average = Math.round(average)
document.write("<h1>"+average+"</h1>")
}
else
{
total = 0
for(i=100;i<=300;i++)
{num=Math.random();
total +=num}
average = total
average = Math.round(average)
document.write("<h1>"+average+"</h1>")