Help with rock, paper scissors!

Hello!

So after several hours of frustrations and searching the forums to no avail here I am for help.

I am new to coding / JS and working on rock, paper, scissors. when running the code below the console returns a tie game no matter what choice1/choice2 show. Ideas?

Thanks!

function computerChoice () {
    var rps = ["rock", "paper", "scissors"];
    var play = rps[Math.floor(Math.random()*rps.length)];
    return play;
}

var choice1 = computerChoice()
var choice2 = "rock"



function playRound (choice1, choice2) {
    if (choice1 === choice2 ) { 
        return "tie!";     
    }
    else if (choice1 === "rock") {
        if (choice2 === "scissors") {
            return "win!";
        }
        else { 
            return "lose!";
        };
    }
    else if (choice1 === "paper") {
        if (choice2 === "scissors") {
            return "win!";
        }
        else {
            return "lose!";
        };
    }
    else { if (choice2 === "rock") {
            return "win!";
        }
        else {
            return "lose!";
        };
    };
};



console.log(playRound())
console.log(choice1)
console.log(choice2)
1 Like

when you call the playRound function, you give no arguments, while in most languages this will give a warning or even an error, JS just gives the parameters an undefined value. (technically, its then the absence of a value)

undefined will equal undefined, so you always get a tie

1 Like

Awesome!

That fixed it!

Thanks!

1 Like