I have made a dice game, similar to yahtzee aka yatzy; pretty much everything works (algorthems that check to see if you have a full house or a small straight, etc..) but only about 3 out of 4 times. I've isolated the issue down to this simple function which determines what dice the player has and inserts those values into an array. The dice are displayed as .gif images with the names 1.gif, 2.gif... 6.gif. (each die is displayed in a <img> with an id from 0-5) Here is the function:
var theDice = new Array();
var path = document.getElementById(i).src;
theDice[i] = path.substring(path.lastIndexOf('/')+ 1, path.lastIndexOf('.'));
so, if you have a 1, a 2, a 3, a 4, and a 5 showing, then it would return 1,2,3,4,5. Many other functions depend on this function, obiviously... and it works most of the time but sometimes it would return 0,2,3,4,5 or 1,2,0,4,5, etc... from what I can tell there doesn't seem to be any pattern... sometimes it's the first element, sometimes it the 3rd could be any, sometimes it's a 1 that is a 0 sometimes it a 6... and all in between... to me it really makes no sense at all how this could be happening intermittently like this, I think I'm minsunderstaning something really basic and low-level about the way JS is working here... any ideas?