I'm having issues with my code for a yahtzee program. Something is wrong with my second switch statement. The results are not being calculated, and printed on the screen. I'm still a beginner, so I'm having trouble deciphering what I did wrong.
Here's the code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
</head>
<body>
<button type="button" onClick="throwDie()">Click To Play Yahtzee</button>
<script>
function throwDie()
{
var dieNum = new Array (12);
var dieValue = new Array (6);
var count = 0;
for ( var i = 0; i <= 12; i++ )
{
var randthrow = Math.floor( (Math.random() *6) +1 );
dieNum[i] = randthrow;
}
Basic game layout. It has no checks for winners/losers, dice sum or other fancy displays.
Might simplify your convoluted (to me) logic and make it easier to modify and add effects.
var baseURL = "http://people.bridgewater.edu/~vcapacci/Classes/2012-Fall-CSCI330/PA%27s/PA2/Dice/";
var dieImg = ['die1.png','die2.png','die3.png','die4.png','die5.png','die6.png'];
var dieNum = [0,0,0,0,0];
var dieValue = [1,2,3,4,5,6];
function startGame() {
dieNum = [0,0,0,0,0];
for (var i=0; i<dieNum.length; i++) { document.getElementById('cb'+i).checked = false; }
throwDie();
}
function throwDie() {
for (var d=0; d<dieNum.length; d++) {
var randthrow = Math.floor((Math.random()*dieValue.length));
if (document.getElementById('cb'+d).checked) { } else { dieNum[d] = randthrow; }
}
var str = '';
for (var d=0; d<dieNum.length; d++) {
var tmp = baseURL+dieImg[dieNum[d]];
document.getElementById('die'+d).src = tmp;
str += document.getElementById('die'+d).src+'\n';
} // alert(str); // alert(dieNum.join(','));
}
</script>
</body>
</html>
Post back if you have questions about set-up or ideas about going forward.