technicka.netfrom the cerebrum of Becky Gessler

Basic JavaScript for loop

This is a very simple script that shows how a basic for loop works. We have an HTML document with 10 empty divs, all given an ID 0-9. (Remember that JavaScript is 0 based so numbers basically always start at 0 and it's a good idea to just conform rather than fight it). Our script uses a for loop to create a random number and insert it into the DIVs. Check the notes in the script to see in more detail how a for loop works.

The HTML page




	my for loop

basic for loop


New #s plz /body> /html>

Da Script

window.onload = initAll;

function initAll() {
	for (var i=0; i

Filed Under

Related Content

I pwn

Oh hai, my name is Becky and this is my personal website about tech and sometimes my life. I work as a user experience designer for UniversityNow, and I live in San Francisco but I bleed New York.