Skip to content

Commit

Permalink
Add click Hold eventListener to add current rolled score to player's …
Browse files Browse the repository at this point in the history
…main score
  • Loading branch information
kenvilar committed Dec 3, 2017
1 parent 9c51b27 commit 051d079
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var scores, roundScore, activePlayer;
var scores, rolledScore, activePlayer;

scores = [0, 0]; // Player 1 and Player 2
roundScore = 0; // Initial Score for round score
rolledScore = 0; // Initial Score for rolled score
activePlayer = 1; // Current active player

document.querySelector('#name-1').textContent = 'PLAYER 1';
Expand Down Expand Up @@ -29,14 +29,14 @@ document.querySelector('.btn-roll-dice').addEventListener('click', function () {
//Update round score if the rolled number is not 1
if (dice !== 1) {
//Add score
roundScore = roundScore + dice;
document.querySelector('#current-' + activePlayer).textContent = roundScore;
rolledScore = rolledScore + dice;
document.querySelector('#current-' + activePlayer).textContent = rolledScore;
} else {
//Next player
document.getElementById('current-1').textContent = '0';
document.getElementById('current-2').textContent = '0';

roundScore = 0;
rolledScore = 0;

activePlayer === 1 ? activePlayer = 2 : activePlayer = 1;

Expand All @@ -48,6 +48,11 @@ document.querySelector('.btn-roll-dice').addEventListener('click', function () {
}
});

document.querySelector('.btn-hold').addEventListener('click', function () {
//Add player current rolled score to his/her main score
scores[activePlayer] = scores[activePlayer] = rolledScore;
});


///////
// document.querySelector('#current-' + activePlayer).textContent = dice; //Select the element
Expand Down

0 comments on commit 051d079

Please sign in to comment.