First page Back Continue Last page Image
- window.onload = initAll;
- function initAll() {
- for (var i=0; i<24; i++) {
- var newNum = Math.floor(Math.random() * 75) + 1;
- document.getElementById("square" + i).innerHTML = newNum;
- }
- }
- When the page loads call the initAll function
- Starting at index 0, increment by 1 each loop and continuing as long as the index in less than 24
- BTW, we also created a variable called "i" here
- We are getting a random number here, but I will explain this line in detail a few slides later
- Find the square with the id "squarei", keeping in mind "i" will be a number between 0 and 23
- Put the new random number we got on the grey line into the table square with the "squarei" id