Error is using random variables


#1

Error
Oops, try again. Your code returned 'The result is a tie' instead of 'undefined' when the inputs are scissors and rock
Results
rock (user)
rock (computer)
The result is a tie

I'm on 8, but I've had the same error in 7, but it worked eventually.
Also, where do you put semicolons, if any?

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(userChoice)
console.log(computerChoice)

var compare = function(){
    if(userChoice === computerChoice) {
    return "The result is a tie"
    }

else if(userChoice === "rock") {

    if(computerChoice === "scissors") {
        return "rock wins"
    }else if(computerChoice === "paper"){
        return "paper wins"}
}
else if(userChoice === "paper"){
if(computerChoice === "rock"){
    return "paper wins"
}else if(computerChoice === "scissors"){
    return "scissors wins"
}
}
else if(userChoice === "scissors"){
    if(computerChoice === "rock"){
        return "rock wins"
    }else if(computerChoice === "paper"){
        return "scissors wins"
    }
}
}

var compareResult = (compare(userChoice,computerChoice))

console.log(compareResult)

#2

You're missing a closing } here:

else if(userChoice === "rock") {
    if(computerChoice === "scissors") {
        return "rock wins"
    }else if(computerChoice === "paper"){
        return "paper wins"}
    }
} // <-- this one

Also you're not making use of parameters. That alone is not a problem as it works as well with global variables, although this is not the best option. The problem is probably that the test function expects parameters meaning when it calls your function with e.g. compare("rock","scissors") it doesn't expect that you completely ignore the parameters and take global variables instead :smile: