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 variable?
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 <div id="demo"> and then use the function to create text inside of it like this:
var i = 0;
while(i < 100){
document.getElementById("demo").innerHTML += "<p>The number is " + i + "</p>";
i++;
}
returnstatement needs to be inside a function. What are you trying to do anyway?returnstatement directly inside awhileloop will result in only one iteration being executed. (It makes your loop useless). However, if you replace this line with something likeconsole.log(i);, it should print 0, 1, ..., 99 to the console.return "the number is " + iwithconsole.log("the number is " + i), press F12, choose the "console" tab, press F5 (assuming that your code is embedded into a web page).