JavaScript初学者:做while循环重复

时间:2014-11-04 09:21:17

标签: javascript

我不知道为什么代码不能重复问问题......然后我把它放在那里......没有任何功能......

<script type='text/javascript'>
var done;
do{
var num = prompt("Enter Number", "0") //prompt user to enter the number
number = parseInt(num); //parse the num to number
var i;

document.write('<table border="1" cellspacing="0">');
for(i=1;i<=12;i++) 
    {
    document.write("<tr><td>" + i  + " x " + number + " = " + number*i + "</td></tr>");
    }
    document.write("</table>");
}while(window.confirm("Do you want to enter another number to show another multiplication table?")



</script>

2 个答案:

答案 0 :(得分:0)

你在} while ... line

上缺少一个括号结尾
<script type='text/javascript'>
var done;
do{
  var num = prompt("Enter Number", "0") //prompt user to enter the number
  number = parseInt(num); //parse the num to number
  var i;

  document.write('<table border="1" cellspacing="0">');
  for(i=1;i<=12;i++) 
  {
    document.write("<tr><td>" + i  + " x " + number + " = " + number*i + "</td></tr>");
  }
  document.write("</table>");
}while(window.confirm("Do you want to enter another number to show another multiplication table?"))

答案 1 :(得分:0)

我认为您忘记了')'符号来关闭while

jsfiddle

while(
    window.confirm(
        "Do you want to enter another number to show another multiplication table?"
     )
) // <- This one