Rock Paper Scissors x99

Hi, I’m on the Rock Paper Scissors Cumulative project and I’m stuck on the getRoundWinner function. I’ve cleared all of the tests so far but I’m not able to get it to return the correct winner for the 3 rounds. I’ve even watched the solutions video and followed some of what the instructor did what I’ve written is not passing.

let playerOneMoveOneType;

let playerOneMoveTwoType;

let playerOneMoveThreeType;

let playerTwoMoveOneType;

let playerTwoMoveTwoType;

let playerTwoMoveThreeType;

let playerOneMoveOneValue;

let playerOneMoveTwoValue;

let playerOneMoveThreeValue;

let playerTwoMoveOneValue;

let playerTwoMoveTwoValue;

let playerTwoMoveThreeValue;

setPlayerMoves = (player, moveOneType, moveOneValue, moveTwoType, moveTwoValue, moveThreeType, moveThreeValue) =>{

    if (!moveOneType || !moveTwoType || !moveThreeType){

        return;

    }

    if (!moveOneValue || !moveTwoValue || !moveThreeValue){

        return;

    }

    if (moveOneValue < 1 || moveTwoValue < 1 || moveThreeValue < 1){

        return;

    }

    if (moveOneValue > 99 || moveTwoValue > 99 || moveThreeValue > 99){

        return;

    }

    if (moveOneValue + moveTwoValue + moveThreeValue > 99){

        return;

    }

    if (!isValidMoveType(moveOneType) || !isValidMoveType(moveTwoType) || !isValidMoveType(moveThreeType)){

        return;

    }

    if (player === 'Player One'){

        playerOneMoveOneType = moveOneType;

        playerOneMoveOneValue = moveOneValue;

        playerOneMoveTwoType = moveTwoType;

        playerOneMoveTwoValue = moveTwoValue;

        playerOneMoveThreeType = moveThreeType;

        playerOneMoveThreeValue = moveThreeValue;

   } else if (player === 'Player Two'){

       playerTwoMoveOneType = moveOneType;

       playerTwoMoveOneValue = moveOneValue;

       playerTwoMoveTwoType = moveTwoType;

       playerTwoMoveTwoValue = moveTwoValue;

       playerTwoMoveThreeType = moveThreeType;

       playerTwoMoveThreeValue = moveThreeValue;

   } else {

       return;

    }

};

isValidMoveType = (moveType) =>{

    return (moveType === 'rock') || (moveType === 'paper') || (moveType === 'scissors');

};

getRoundWinner = (roundNumber) =>{

    switch (roundNumber){

        case 1:

            return getMoveWinner(playerOneMoveOneType, playerOneMoveOneValue, playerTwoMoveOneType, playerTwoMoveOneValue);

        case 2:

            return getMoveWinner(playerOneMoveTwoType, playerOneMoveTwoValue, playerTwoMoveTwoType, playerTwoMoveTwoValue);

        case 3:

             return getMoveWinner(playerOneMoveThreeType, playerOneMoveThreeValue, playerTwoMoveThreeType, playerTwoMoveThreeValue);

        default:

            return null;

    }

};

getMoveWinner = (playerOneMoveType, playerOneMoveValue, playerTwoMoveType, playerTwoMoveValue ) =>{

    if (!playerOneMoveType || !playerOneMoveValue || !playerTwoMoveType || !playerTwoMoveValue){

        return null;

    }

    if (playerOneMoveType === playerTwoMoveType){

        if (playerOneMoveValue > playerTwoMoveValue){

            return 'Player One';

        } else if (playerOneMoveValue < playerTwoMoveValue){

            return 'Player Two';

        } else {

            return 'Tie';

        }

    }

    if (playerOneMoveType === 'rock'){

        if (playerTwoMoveType === 'scissors'){

            return 'Player One';

        } else {

            return 'Player Two';

        }

    } else if (playerOneMoveType === 'rock'){

        if (playerTwoMoveType === 'paper'){

            return 'Player Two';

        } else {

            return 'Player One';

        }

    } else {

        if (playerTwoMoveType === 'scissors'){

            return 'Player Two'

        } else {

            return 'Player One';

        }

    }

}

Welcome to the forums :slight_smile:

I would put console.log statements in the area you think is being affected that reflect the incoming inputs.

Consider using template literals for this purpose, as they can enhance clarity and speed your search, for example:

let some_variable = 10;
console.log(`some_variable value is: ${some_variable}`);
// output:
// "some_variable value is: 10"

In terms of your variable declarations, consider there’s a principle in programming called DRY (don’t repeat yourself). Is there a way to structure your code so you use fewer declarations?

Thank you!

Tbh I realized reading your comment that although I’ve done the lessons referring to things like template literals I still don’t understand how I would actually use them and I feel like I didn’t absorb what came before enough to solve this so I’m choosing to re-review the past lessons. I’ll try to take your advice into account once I reach this point again.

1 Like

How did you solve the problem? I have the same issue.