for loop: Set the counter variable (i) to 0, Run the loop as long as i is less than the length of the food array. - Javascript Statement

Javascript examples for Statement:Quiz

Description

for loop: Set the counter variable (i) to 0, Run the loop as long as i is less than the length of the food array.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
var text = "";
var food = ["yes", "B", "T", "F", "C"];
var i;/*w  ww . j a v a 2 s. c  o  m*/

for (i = 0; i < food.length; i++) {
    text += "I love " + food[i] + "<br>";
}

document.getElementById("demo").innerHTML = text;
</script>

</body>
</html>

Related Tutorials