Javascript, while loop return

后端 未结 3 901
时光说笑
时光说笑 2020-12-20 17:54
var i = 0;
while(i < 100){
   return \"The number is \" + i;
   i++;
}

What is wrong with my return statement? Why can I return a string plus a

3条回答
  •  旧时难觅i
    2020-12-20 18:16

    I'm not exactly sure what you want to do with this text, but return will take you out of the function. If you want to display this text, you could use

    and then use the function to create text inside of it like this:

    var i = 0;
    while(i < 100){
        document.getElementById("demo").innerHTML += "

    The number is " + i + "

    "; i++; }

    http://jsfiddle.net/rmerzbacher/fdu7aauz/

提交回复
热议问题