Updating Arrays

As you saw in Figure 3.4, the Bingo card script doesn’t yet have a way to make sure that duplicate numbers don’t appears in a given column. This example fixes that problem, while simultaneously demonstrating that arrays don’t have to be just initialized and then read—instead, they can be declared and then set on the fly. This gives you a great deal of flexibility, since you can use calculations or functions to change the values in the array while the script is running. Script 3.8 shows you how, with only a few new lines of code.

Script 3.8. Changing the contents of arrays to store the current situation is a very powerful technique.
window.onload = initAll;
var usedNums = new Array(76); function initAll() { if (document.getElementById) ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.