这个代码应该怎么写?

我想打印从1到100 并且把能处以7的整数替换成haha 我这么写为什么不对?应该怎么写?
<html>
<head>
<title>无
</title>
<type style>
</style>
<script type="text/javascript">
for (var i=0; i<=100; i++)
{
x=i+1;
if(x%7){
document.write(haha)}
else{
document.write(x)};
}

</script>

</head>
<body>

</body>
</html>

第1个回答  2014-02-24
<script type="text/javascript">
for (var i=1; i<=100; i++)
{
if(i%7==0){
document.write('haha'+' ');
}
else{
document.write(i+' ');
}
}
</script>
“ x=i+1”就会使每次循环加2;
还有‘haha’如果是变量的话直接写就可以了 如果是字符串需要加单引号 ' 或者双引号”
第2个回答  2014-02-24
<html>
<head>
<title>无
</title>
<type style>
</style>
<script type="text/javascript">
for (var i=0; i<=100; i++)
  {
    x=i+1;
    if(x%7==0){
    document.write("haha")
}else{
    document.write(x)};
  }
</script>
</head>
<body>
</body>
</html>

你的代码的问题是:
1,字符串写到页面要加上引号。

document.write("haha")

2,判断的时候if(x%7==0)加上==0

第3个回答  2014-02-23
for (var i=0; i<=100; i++)
{
x=i+1;
if(x%7==0){
document.write("haha")}
else{
document.write(x)};
}本回答被提问者采纳
相似回答