Checking State

Along with interaction to let the user set a square, we can also check to see if the squares form a winning pattern. In this penultimate example, the user checks off which numbers have been called, and then Script 3.12 lets the user know when they’ve won.

Script 3.12. Complex math makes this script simple: a winning combination.
window.onload = initAll; var usedNums = new Array(76); function initAll() { if (document.getElementById) { document.getElementById("reload").onclick = anotherCard; newCard(); } else { alert("Sorry, your browser doesn't support this script"); } } function newCard() { for (var i=0; i<24; i++) { setSquare(i); } } function setSquare(thisSquare) { var currSquare = "square" + thisSquare; var colPlace = new Array(0,0,0,0,0,1,1,1,1,1,2,2,2,2,3,3,3,3,3,4,4,4,4,4); ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.