Adding more if / else statements

If the user chooses rock and the computer chooses scissors, are those conditions covered ? it does not seem like they are.

// Define a 'const' function for determining a winner.
const determineWinner = (userChoice, computerChoice) => {

    if (userChoice === computerChoice) {

        return "This game is a tie";
    
    } 
    if (userChoice === "rock") {

        if (computerChoice === "paper") {

            return "The winner is the computer";
        
        } 
        
        return "The winner is the user";
        
    }

    if (userChoice === "paper") {

        if (computerChoice === "scissors") {

            return "The winner is the computer";
        
        } 
        
        return "The winner is the user";
        
    }

    if (userChoice === "scissors") {

        if (computerChoice === "rock") {

            return "The winner is the computer";
        
        } 
        
        return "The winner is the user";
        
    }

};

No, I believe that possibility is covered. The code states that if the user chooses rock than it will see if the computer chose paper. If the computer didn’t choose paper, it already knows that it is not a tie, so it runs:

return "The winner is the user";

Hopefully that is helpful :grinning:

Yup. I think have it understood now.
Thanks.

1 Like