Skip to content

Commit

Permalink
Change anonymous function to reset callback functon and moved the fir…
Browse files Browse the repository at this point in the history
…st initialize statement to the reset function
  • Loading branch information
kenvilar committed Dec 3, 2017
1 parent 018dc18 commit c855942
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
var scores, rolledScore, activePlayer;

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

document.querySelector('#name-1').textContent = 'PLAYER 1';
document.querySelector('#name-2').textContent = 'PLAYER 2';

document.querySelector('#dice-1').style.display = 'none';
document.querySelector('#dice-2').style.display = 'none';

document.getElementById('score-1').textContent = '0';
document.getElementById('score-2').textContent = '0';
document.getElementById('current-1').textContent = '0';
document.getElementById('current-2').textContent = '0';
reset();

document.querySelector('.btn-roll-dice').addEventListener('click', function () {
//Random number
Expand Down Expand Up @@ -58,11 +45,7 @@ document.querySelector('.btn-hold').addEventListener('click', function () {
}
});

document.querySelector('.btn-new-game').addEventListener('click', function () {
scores = [0, 0];
rolledScore = 0;
activePlayer = 1;
});
document.querySelector('.btn-new-game').addEventListener('click', reset);

function nextPlayer() {
document.getElementById('current-1').textContent = '0';
Expand All @@ -79,6 +62,23 @@ function nextPlayer() {
document.querySelector('#dice-2').style.display = 'none';
}

function reset() {
scores = [0, 0];
rolledScore = 0;
activePlayer = 1;

document.querySelector('#name-1').textContent = 'PLAYER 1';
document.querySelector('#name-2').textContent = 'PLAYER 2';

document.querySelector('#dice-1').style.display = 'none';
document.querySelector('#dice-2').style.display = 'none';

document.getElementById('score-1').textContent = '0';
document.getElementById('score-2').textContent = '0';
document.getElementById('current-1').textContent = '0';
document.getElementById('current-2').textContent = '0';
}


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

0 comments on commit c855942

Please sign in to comment.