B I N G O
         
         
    Free    
         
         

Below is the commented JavaScript code for the bingo card.

//intialize the page and create the array usedNums
window.onload = initAll;
var usedNums = new Array(76);
function initAll()
{ if(document.getElementById){
//find the "Click here" link and call the anotherCard function (see below)
document.getElementById("reload").onclick = anotherCard;
newCard(); }
else{
alert("Sorry your browser does not support this script"); } }
//runs through each square of the bingo card and calls setSquare function (see below)
function newCard(){
for (var i=0; i< 24; i++){
setSquare(i); } }
//this picks up the "square" string which is the first part of tne name of each td id //and concatenates to the i'th number to give it it's full name //the colPlace array holds the number spaces with the middle column not having column 2 //colBasis multiplies whatever the number of the square is in the array by 15
function setSquare(thisSquare){
var currSquare = "square" + thisSquare;
var colPlace = new Array (0,1,2,3,4,0,1,2,3,4,0,1,3,4,0,1,2,3,4,0,1,2,3,4);
var colBasis = (colPlace[thisSquare] * 15);
var newNum;
//newNum var is set to colBasis + getNewNum function +1 (see below)
do{ newNum = colBasis + getNewNum() + 1; }
//as the numbers in the useNums array 1 - 76 are found the newNum is changed to a usedNums and the // number is added to the current square
while(usedNums[newNum]) usedNums[newNum] = true; document.getElementById(currSquare).innerHTML = newNum; }
// returns a random number between 0 and 1 and multiplies by 15
function getNewNum(){ return Math.floor(Math.random() * 15) }
//run through the usedNums array and call newCard function (see above)
function anotherCard(){
for (var i=1; i < usedNums.length; i++){
usedNums[i] = false; }
newCard();
// the javascript functions have been called with having to go to the server to refresh page
return false; }