Rock Paper Scissors x99 | getGameWinner problems with "Tie"

Hi! I hope you have a great day!

I’m currently working on the Rock Paper Scissors x99 Project.

The whole code until now looks like this:

let playerOneMoveOneType
let playerOneMoveTwoType
let playerOneMoveThreeType

let playerTwoMoveOneType
let playerTwoMoveTwoType
let playerTwoMoveThreeType

let playerOneMoveOneValue
let playerOneMoveTwoValue
let playerOneMoveThreeValue

let playerTwoMoveOneValue
let playerTwoMoveTwoValue
let playerTwoMoveThreeValue

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

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

        playerOneMoveOneType = moveOneType;
        playerOneMoveTwoType = moveTwoType;
        playerOneMoveThreeType = moveThreeType;
        
        playerOneMoveOneValue = moveOneValue;
        playerOneMoveTwoValue = moveTwoValue;
        playerOneMoveThreeValue = moveThreeValue;

        }
    else if (player === "Player Two"){
        playerTwoMoveOneType = moveOneType;
        playerTwoMoveTwoType = moveTwoType;
        playerTwoMoveThreeType = moveThreeType;

        playerTwoMoveOneValue = moveOneValue;
        playerTwoMoveTwoValue = moveTwoValue;
        playerTwoMoveThreeValue = moveThreeValue;

        }
    else {return 'Incorrect Input'}
      }

const getRoundWinner = round => {  
    
    if (round = 1){
        if (playerOneMoveOneType === "rock" && playerTwoMoveOneType === "scissors"){
            return "Player One"}
        else if (playerOneMoveOneType === "scissors" && playerTwoMoveOneType === "rock"){
            return "Player Two"}
        else if  (playerOneMoveOneType === "rock" && playerTwoMoveOneType === "paper"){
            return "Player Two"}
        else if (playerOneMoveOneType === "paper" && playerTwoMoveOneType === "rock"){
                return "Player One"}
        else if  (playerOneMoveOneType === "scissors" && playerTwoMoveOneType === "paper"){
            return "Player One"}
        else if (playerOneMoveOneType === "paper" && playerTwoMoveOneType === "scissors"){
                return "Player Two"}
        else if (playerOneMoveOneType === playerTwoMoveOneType) {
            if (playerOneMoveOneValue > playerTwoMoveOneValue) {return "Player One"}
            else if (playerOneMoveOneValue < playerTwoMoveOneValue) {return "Player Two"}
            else if (playerOneMoveOneValue ===  playerTwoMoveOneValue) {return "Tie"}}


    }

    else if (round = 2){
        if (playerOneMoveTwoType === "rock" && playerTwoMoveTwoType === "scissors"){
            return "Player One"}
        else if (playerOneMoveTwoType === "scissors" && playerTwoMoveTwoType === "rock"){
            return "Player Two"}
        else if  (playerOneMoveTwoType === "rock" && playerTwoMoveTwoType === "paper"){
            return "Player Two"}
        else if (playerOneMoveTwoType === "paper" && playerTwoMoveTwoType === "rock"){
                return "Player One"}
        else if  (playerOneMoveTwoType === "scissors" && playerTwoMoveTwoType === "paper"){
            return "Player One"}
        else if (playerOneMoveTwoType === "paper" && playerTwoMoveTwoType === "scissors"){
                return "Player Two"}
        else if (playerOneMoveTwoType === playerTwoMoveTwoType) {
            if (playerOneMoveTwoValue > playerTwoMoveTwoValue) {return "Player One"}
            else if (playerOneMoveTwoValue < playerTwoMoveTwoValue) {return "Player Two"}
            else if (playerOneMoveTwoValue ===  playerTwoMoveTwoValue) {return "Tie"}}
        }

    else if (round = 3){
        if (playerOneMoveThreeType === "rock" && playerTwoMoveThreeType === "scissors"){
            return "Player One"}
        else if (playerOneMoveThreeType === "scissors" && playerTwoMoveThreeType === "rock"){
            return "Player Two"}
        else if  (playerOneMoveThreeType === "rock" && playerTwoMoveThreeType === "paper"){
            return "Player Two"}
        else if (playerOneMoveThreeType === "paper" && playerTwoMoveThreeType === "rock"){
                return "Player One"}
        else if  (playerOneMoveThreeType === "scissors" && playerTwoMoveThreeType === "paper"){
            return "Player One"}
        else if (playerOneMoveThreeType === "paper" && playerTwoMoveThreeType === "scissors"){
                return "Player Two"}
        else if (playerOneMoveThreeType === playerTwoMoveThreeType) {
            if (playerOneMoveThreeValue > playerTwoMoveThreeValue) {return "Player One"}
            else if (playerOneMoveThreeValue < playerTwoMoveThreeValue) {return "Player Two"}
            else if (playerOneMoveThreeValue ===  playerTwoMoveThreeValue) {return "Tie"}}
        }
}

const getGameWinner = () => {
    

    let GameWinnerOne = 0;
    let GameWinnerTwo = 0;


    if (getRoundWinner(1) === "Player One"){GameWinnerOne +=1 }
    else if (getRoundWinner(1) === "Player Two"){GameWinnerTwo +=1 };
   
    if (getRoundWinner(2) === "Player One"){GameWinnerOne +=1}
    else if (getRoundWinner(2) === "Player Two"){GameWinnerTwo +=1};

    if (getRoundWinner(3) === "Player One"){GameWinnerOne +=1}
    else if (getRoundWinner(3) === "Player Two"){GameWinnerTwo +=1};

    if (GameWinnerOne > GameWinnerTwo) {return "Player One"}
    else if (GameWinnerOne < GameWinnerTwo) {return "Player Two"}
    else if (GameWinnerOne === GameWinnerTwo)  {return "Tie"};

}

I have ignored the edge-cases for now and focused on the main functionality first.
The main functionality works fine up until the point that the endresult would be a tie. This part of the code:

const getGameWinner = () => {
    

    let GameWinnerOne = 0;
    let GameWinnerTwo = 0;


    if (getRoundWinner(1) === "Player One"){GameWinnerOne +=1 }
    else if (getRoundWinner(1) === "Player Two"){GameWinnerTwo +=1 };
   
    if (getRoundWinner(2) === "Player One"){GameWinnerOne +=1}
    else if (getRoundWinner(2) === "Player Two"){GameWinnerTwo +=1};

    if (getRoundWinner(3) === "Player One"){GameWinnerOne +=1}
    else if (getRoundWinner(3) === "Player Two"){GameWinnerTwo +=1};

    if (GameWinnerOne > GameWinnerTwo) {return "Player One"}
    else if (GameWinnerOne < GameWinnerTwo) {return "Player Two"}
    else if (GameWinnerOne === GameWinnerTwo)  {return "Tie"};

}

It looks beautiful to me, but when I run the test, I get this resut:

getGameWinner() - Main Functionality
should declare when game is a tie:

AssertionError: expected 'Player Two' to equal 'Tie'
+ expected - actual

-Player Two
+Tie

I have not the slightest idea, what the issue might be. I tried several other ways to solve the issue, but besides the fact that it just got more and more and more code, I truely want to understand the issue here, but no matter how long I stare at it, I can’t see the problem.

I would highly appreciate any help. Thank you!

Haven’t gone through the whole code. Skimming through it, these seem to be wrong:

if (round = 1)
...
else if (round = 2)
...
else if (round = 3)

You probably meant to use the comparison operator instead of assignment operator.

1 Like

Thank you, highly appreciated! This was exactly the issue.

I hope, one day I’ll stop to use = instead of === sigh
My big lesson learned: Don’t fixiated only on a little part of the code.

Thanks so much and have a great day!

1 Like