The following code is used here to randomly pick a number in a bingo game. It works fine in IE but in Firefox it displays "undefined" for the number just drawn. When I placed an alert after the line:
var r = Math.floor(Math.random() * j); // Pick one from those remaining
to display r, I got "NaN". The genform() function worked fine though.
TIA
Code:<script language="JavaScript"> var deck = new Array(75); var history = ""; var j; function genform() { for (var i=0; i < 75;i++) { document.bingo.elements[i].value = formatR(i + 1); document.bingo.elements[i].style.color = "#cacaca"; document.bingo.elements[i].style.backgroundColor = "#ffffff"; deck[i] = i + 1; } document.bingo.lastcalled.value = ""; document.bingo.history.value = ""; history = ""; j = 74; } function callone() { var bingolit = [ "B", "I", "N", "G", "O"] ; if (j < 0) { alert("No more numbers to draw"); return 1; } var r = Math.floor(Math.random() * j); // Pick one from those remaining var drawn = deck[r]; deck[r] = deck[j]; // Move last of those remaining to slot just chosen if (j <74) { if (history.length > 0) history+= "\n"; // history += document.bingo.lastcalled.value; history = document.bingo.lastcalled.value + "\n" + history; document.bingo.history.value = history; } document.bingo.lastcalled.value = bingolit[Math.floor((drawn-1)/15)] + ' ' + drawn; document.bingo.elements[drawn - 1].style.color = "#000000"; document.bingo.elements[drawn - 1].style.backgroundColor = "#ffff00"; j--; } function formatR (x) { if (x < 10) return ' ' + x; else return x;} //Right justify


Reply With Quote

Bookmarks