mardi 29 mai 2018

Why does this if statement work but this other solution does not?

Im doing this for a dice game where the player is switched if either dice rolled is a 1 or if 6 is rolled twice in a row. My friends code worked but mine didn't, It looks like my if statement accomplishes the same thing.

This code works(friends code):

if (dice === 1 || diceTwo === 1) {
    nextPlayer();
} else if (doubleSix === 6) {
    if (dice === 6 || diceTwo === 6) {
        roundScore = 0;
        score[activePlayer] = 0;
        nextPlayer();
    }
} else {
    roundScore += (dice + diceTwo);
    document.querySelector('#current-' + activePlayer).textContent = roundScore;
    doubleSix = dice;
}

This code does not (my code):

if (dice !== 1 || diceTwo !== 1) {
    //Add score
    if (doubleSix === 6 && dice === 6) {
        roundScore = 0;
        score = 0;
        nextPlayer();
    } else if {
        roundScore += (dice + diceTwo) ;
        document.querySelector('#current-' + activePlayer).textContent = roundScore;
        doubleSix = dice;
    }
    } else {
    //Next Player
    nextPlayer();
}

Aucun commentaire:

Enregistrer un commentaire