"The result is a tie" - always


#1

No matter what I type in when the computer asks me to choose, it's always a tie, even if I choose "rock" and the computer e.g. "paper". What's wrong with my code?


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);

var compare = function (choice1, choice2) {
    if (choice1 === choice2) {
        return "The result is a tie!";
        }
    
    else if (choice1 === "rock") {
        
        if(choice2 === "scissors") {
            return "rock wins";
            }
        
        else {
            return "paper wins";
            }
        
        }
    
    else if (choice1 === "scissors") {
        
        if(choice2 === "paper") {
            return "scissors wins";
            }
        
        else {
            return "rock wins";
            }
        
        } 
    
    else if (choice1 === "paper") {
        
        if(choice2 === "scissors") {
            
            return "scissors wins";
            
            }
        
        else {
            return "paper wins";
            }    
        
        }
    
    }
    
    compare();


#2

Hi you should read what the error you got says..
Oops, try again. Make sure to call your compare function with userChoice and computerChoice as the arguments!

compare();#you should put the arguments userChoice and computerChoice inside the call function

#3

yaaay!! thaaaanks for your help, it works now! ^_^


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.