For Loops in JavaScript

Below is an example of  a for loop from JavaScript. Have a look and see if you understand how it works: 

var fruits = ["peach", "orange", "Apple"];

for (var i = 0; i<fruits.length; i++)
{
//we are now inside our loop.
document.write("value of i is: " + i);

//this is the html for a new line.
document.write("<br>");

document.write("the fruit at i is: " + fruits[i]);

document.write("<br>");
}

No comments:

Post a Comment

Web Development: Organizing Files and Folders

When you begin to build your website, it's a very clever idea to organize  your files and folders efficiently. You should have: A ...