|
Here's the script:
var height = prompt("How
high do you want the grid? (1 - 10 is good)", "10");
var width = prompt("How wide
do you want the grid? (1 - 10 is good)", "10");
var aLine;
var newWindow = window.open("grid.htm",
"looper", "width=400,height=400");
newWindow.document.write("<H1>A
Grid</H1>");
| for (i = 0; i < height; i++) { |
| aLine = ""; |
| for (j = 0; j <
width; j++) { |
|
aLine += "x"; |
| } |
| newWindow.document.write(aLine
+ "<BR>"); |
| } |
After asking for height and width, opening a new window, and writing
a header to it, we go into a for loop. The first for loop sets aLine =
"". Try doing the example without this line and see what
happens.
After initializing aLine, the script goes into another for loop to
build a line of x's as wide as required and prints it out to the new
window. This happens height times. |