Gettin stuck and frustrated about it...... need help!


#1

So far so good.... in case i run the code the little guy always checking my code tells me to take a look on the arguments of my function. i can't find anything wrong and don't know how to proceed, pls help me!

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
	computerChoice = "rock";
} else if(computerChoice <= 0.67) {
	computerChoice = "paper";
} else {
	computerChoice = "scissors";
} 
console.log("Computer: " + computerChoice);
console.log("User: " + userChoice);

var compare = function ( computerChoice , userChoice)  {
    if (userChoice === computerChoice) {
        return ("The result is a tie!");
    }
    else if (userChoice === "rock") {
        if (computerChoice === "scissors") {
            return "rock wins";
        }
        else {
            return "paper wins";
        }
    }
    else if (userChoice === "paper") {
        if (computerChoice === "rock") {
            return "paper wins";
        }
        else {
            return "scissors wins";
        }
    }
    else if (userChoice === "scissors"){
        if (computerChoice === "paper") {
            return "scissors wins";
        }
        else {
            return "rock wins";
        }
    }
}
console.log (compare);

#2

You have to invoke the function compare with brackets and 2 arguments - computer choice and user choice.

compare(computerChoice, userChoice);

#4

That's true.
It's userChoice, not userChoise


#5

got it, thank you very much! safed my day!


#6

Also to avoid confusion it is recommended to use choice1 and choice2 instead of userChoice and computerChoice inside of the compare function. The reason is that by using parameters you create a new set of variables, in your case with the same name. But they do not get their value because of their name twins but because of the values you pass to the invoked function. That's where you're userChoice inside the function gets connected to the userChoice outside the function.


#7

all right... i try to :wink: