Skip to content

Commit

Permalink
Next player after current player clicks Hold button and updating his/…
Browse files Browse the repository at this point in the history
…her main score
  • Loading branch information
kenvilar committed Dec 3, 2017
1 parent 1c2aff6 commit 14f4660
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ A dice game using pure JavaScript

## Rules
* 2 players needed
* A player rolls a dice in each turn as many times as he/she whishes. Each result gets added to his/her rolled score
* If the player rolls a 1, all his/her roll/s will get lost and no results will be added to his main score. After that, it's the next player's turn
* The player can select to 'Hold', which means that his/her rolled score gets added to his/her main score. After that, it's the next player's turn
* A player rolls a dice in each turn as many times as he/she whishes. Each result gets added to his/her current rolled score
* If the player rolls a 1, all his/her current rolled scores will get lost and no results will be added to the main score. After that, it's the next player's turn
* The player can select to 'Hold', which means that his/her current rolled score gets added to his/her main score. After that, it's the next player's turn
* Any player who will reach 100 points and above on his/her main score wins the game!

# GOOD LUCK! :)
9 changes: 9 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ document.querySelector('.btn-hold').addEventListener('click', function () {
scores[activePlayer - 1] = scores[activePlayer - 1] + rolledScore;

document.querySelector('#score-' + activePlayer).textContent = scores[activePlayer - 1];

document.getElementById('current-1').textContent = '0';
document.getElementById('current-2').textContent = '0';
rolledScore = 0;
activePlayer === 1 ? activePlayer = 2 : activePlayer = 1;
document.querySelector('.player-1-panel').classList.toggle('active');
document.querySelector('.player-2-panel').classList.toggle('active');
document.querySelector('#dice-1').style.display = 'none';
document.querySelector('#dice-2').style.display = 'none';
});


Expand Down

0 comments on commit 14f4660

Please sign in to comment.