To add up the total score you need a variable at the beginning of the roll() function and you need to add the score of every dice thow to the total score. Also since the roll() and rolAgain() functions are the same (except for the "ready to roll" dialog) you can just call the roll() methods for both the start game and play again buttons, or have the rollAgain() function call the roll() function and possibly create a new function for the start game button that just displays the "ready to roll" dialog and calls the roll() function.
<script>
function roll()
{
var totalScore = 0;
var die1 = Math.floor(Math.random()*6 + 1);
var die2 = Math.floor(Math.random()*6 + 1);
score = (die1 + die2)
totalScore = totalScore + score;
alert("Ready to roll!");
alert("You rolled a " + die1 + " and a " + die2 + " for a score of " + score)
var die1 = Math.floor(Math.random()*6 + 1);
var die2 = Math.floor(Math.random()*6 + 1);
score = (die1 + die2)
totalScore = totalScore + score;
alert("You rolled a " + die1 + " and a " + die2 + " for a score of " + score)
var die1 = Math.floor(Math.random()*6 + 1);
var die2 = Math.floor(Math.random()*6 + 1);
score = (die1 + die2)
totalScore = totalScore + score;
alert("You rolled a " + die1 + " and a " + die2 + " for a score of " + score)
var die1 = Math.floor(Math.random()*6 + 1);
var die2 = Math.floor(Math.random()*6 + 1);
score = (die1 + die2)
totalScore = totalScore + score;
alert("You rolled a " + die1 + " and a " + die2 + " for a score of " + score)
var die1 = Math.floor(Math.random()*6 + 1);
var die2 = Math.floor(Math.random()*6 + 1);
score = (die1 + die2)
totalScore = totalScore + score;
alert("You rolled a " + die1 + " and a " + die2 + " for a score of " + score)
alert("Your total score for this game was " + totalScore);
}
</script>
answered
Sep 13 '12 at 04:47
nickjuly4
951●9●16●21