"Make sure to call your compare function with userChoice and computerChoice as the arguments!" - can't find the error in my code


#1

Javascript (8/9) - Rock Paper Scissors

When I run my code it tells me "Oops, try again. Make sure to call your compare function with userChoice and computerChoice as the arguments!" I can't find the issue with my code though... Any assistance would be greatly appreciated.

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(userChoice, computerChoice){
    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 === "rock"){
                    return "rock wins";
                }
                else
                { return "scissors wins";
                }
            }
    }


#2

@indrid_cold,

You where required to build the compare function
taking 2 parameter choice1 and choice2

The return statement's should return lowercase String Value's

Please read
http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b
and concentrate on:

  • the creation of the compare function
  • the truth-table
  • the build of the IF ELSE-IF statement structure as part of the compare FUNCTION-BODY
  • the execution of the compare function (keeping in mind that the return statement is used )

#3

Did you try calling the function compare(userChoice, computerChoice) at the very end?


#4

just call the below statement at the end :
compare(userChoice, computerChoice);


#5

facepalm

Nope. Totally missed actually calling the compare function. Wow. Thanks guys...


#6

You are not alone :relieved:


#7

Thanks for posting this. I did the exact same thing.


#8

can you please give the code and tell me where do i have to put it ?
:blush::writing_hand:


#9

well,thank u very much,hah


#11