function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1) ) + min;
}
function getBingoValues() {
GenBingoVals = [];
//Loop through 5 columns - colCntr
for (colCntr=1; colCntr<=5; colCntr++) {
//Generate Initial Value Array - ColVals
ColVals = [];
initArrayVal = (colCntr-1)*15+1;
//Populate Initial Array
for (i = initArrayVal; i <= (colCntr)*15; i++) {
ColVals.push(i);
}
rowValsSlctd = [];
//Loop Through 5 Rows = rowCntr
for (rowCntr=1; rowCntr<=5; rowCntr++) {
//Identify Random Number for Array POSITION for Col/Row Value
RandPos = getRndInteger(1,ColVals.length);
BingoVal = ColVals[RandPos-1];
//Remove Selected Value from Array
ColVals.splice(RandPos-1,1);
//Add Bingo Value to Row Value array - rowValsSlctd
rowValsSlctd.push(BingoVal);
}
//Sort Row Value array for Usage
rowValsSlctd.sort(function(a, b){return a-b});
//Add Selected / Sorted RowValues to Bingo Number array
GenBingoVals.push(rowValsSlctd);
}
return GenBingoVals;
}
function displayBingoCardNumbers(){
BingoNbrs = [];
BingoNbrs = getBingoValues();
for (r=1; r<=5; r++) {
for (c=1; c<=5; c++) {
cellId = "R".concat(r,"C",c);
document.getElementById(cellId).innerHTML=BingoNbrs[c-1][r-1];
}
}
//Middle Square is FREE
document.getElementById("R3C3").innerHTML="*";
}
function initBingoCard() {
BingoHdr = ["B", "I", "N", "G", "O"];
//Create Bingo Card Table
bingoCard = "<table class=\"BingoTable\">";
//Create Bingo Card Header
bingoCard = bingoCard + "<thead>";
bingoCard = bingoCard + "<tr>";
for (i=1; i<=5; i++) {
bingoCard = bingoCard + "<th>";
bingoCard = bingoCard + BingoHdr[i-1];
bingoCard = bingoCard + "</th>";
}
bingoCard = bingoCard + "</tr>";
bingoCard = bingoCard + "</thead>";
//Create Bingo Card Details
bingoCard = bingoCard + "<tbody>";
for (r=1; r<=5; r++) { //Row Loop Counter
bingoCard = bingoCard + "<tr>";
for (i=1; i<=5; i++) { //Column Loop Counter
cellVal="R" + r + "C" + i;
bingoCard = bingoCard + "<td id=" + cellVal + ">";
bingoCard = bingoCard + cellVal;
bingoCard = bingoCard + "</td>";
}
bingoCard = bingoCard + "</tr>";
}
bingoCard = bingoCard + "</tbody>";
bingoCard = bingoCard + "</table>";
//Update BingoCard in HTML
document.getElementById("BingoCard").innerHTML=bingoCard;
//Populate Bingo Card
displayBingoCardNumbers();
}