I'm adding an else-if block to an if else block for a Pig game in javascript. I added a var called prevRoll that stores the dice value at the end of the block, so the next time it loops it can check to see if the current roll and the previous roll are both 6, then reset score to 0. My else-if block is throwing an error, "Uncaught SyntaxError: Unexpected token {"
I tried removing the block I added to confirm it was the cause of the error, and it is. I double checked all my syntax for the block.
document.querySelector('.btn-roll').addEventListener('click', function(){
if(gamePlaying) {
//1. Random Number
dice = Math.floor(Math.random() * 6) + 1;
var diceDOM = document.querySelector('.dice');
diceDOM.style.display = 'block';
diceDOM.src = 'dice-' + dice + '.png';
if (dice !== 1) {
roundScore += dice;
document.querySelector('#current-' + activePlayer).textContent = roundScore;
}
elseif (dice === 6 && prevRoll === 6) {
scores[activePlayer] = 0;
}
else {
nextPlayer();
}
}
prevRoll = dice;
});
Expected: Game will run normally, and when a player rolls two sixes in a row, they will lose all their points (This won't actually happen yet, I need to create an array to store each player's previous roll, instead of just one variable)
Actual: Throwing error.
Aucun commentaire:
Enregistrer un commentaire