Skip to content

Commit

Permalink
Implement two dices and add each other
Browse files Browse the repository at this point in the history
  • Loading branch information
kenvilar committed Dec 3, 2017
1 parent afc61fd commit efb8256
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ reset();
document.querySelector('.btn-roll-dice').addEventListener('click', function () {
if (isGameActive) {
//Random number
var dice = Math.floor((Math.random() * 6) + 1);
var dice1 = Math.floor((Math.random() * 6) + 1);
var dice2 = Math.floor((Math.random() * 6) + 1);

//Display result
var diceObj = document.querySelector('.dice');
var diceObj1 = document.querySelector('#dice-1');
var diceObj2 = document.querySelector('#dice-2');

diceObj.style.display = 'block';
diceObj1.style.display = 'block';
diceObj2.style.display = 'block';

diceObj.src = 'dice' + dice + '.png';
diceObj1.src = 'dice' + dice1 + '.png';
diceObj2.src = 'dice' + dice2 + '.png';

//Update round score if the rolled number is not 1
if (dice !== 1) {
if (dice1 !== 1 && dice2 !== 1) {
//Add score
rolledScore += dice;
rolledScore += dice1 + dice2;
document.querySelector('#current-' + activePlayer).textContent = rolledScore;
} else {
nextPlayer();
Expand Down Expand Up @@ -63,7 +67,8 @@ function nextPlayer() {
document.querySelector('.player-1-panel').classList.toggle('active');
document.querySelector('.player-2-panel').classList.toggle('active');

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

function reset() {
Expand Down

0 comments on commit efb8256

Please sign in to comment.