dimanche 19 mai 2019

My Function For Rock, Paper, Scissors Is Not Working

I have a function that is suppose to determine the winner of game. For some reason, it will always print the first if statement, even if it is not correct

I have tried making them all if statements, changing the brackets, and I split all the else if statements up instead of having only 3 and nothing is working.

function determineWinner(userButton,compChoice) {
    if (userButton === compChoice) {
        return 'It\'s a tie!';
    }
    else if (userButton === "ROCK" && compChoice === "PAPER") {
        return 'Computer wins!';
    }
    else if (userButton === 'PAPER' && compChoice === 'SCISSORS') {
        return 'Computer wins!';
    } 
    else if (userButton === 'SCISSORS' && compChoice === 'ROCK') {
        return 'Computer wins!';
    }
    else if (userButton === 'PAPER' && compChoice === 'ROCK') 
    {
        return 'You win!';
    }
    else if (userButton === 'SCISSORS' && compChoice === 'PAPER') {
        return 'You win!';
    } 
    else {
        return 'You win!';
    }

}

The output is suppose to show either computer wins, you win, or its a tie. It shows its a tie every single time.

Aucun commentaire:

Enregistrer un commentaire