Build "Rock, Paper, Scissors" / Both choices are the same!


#1

hello,
I keep getting this error message: "Oops, try again.
Did you create a function called compare?"

here's my code so far:(what am I doing wrong?)

/*var userChoice = prompt("Do you choose rock, paper or scissors?");
var compare = function(choice1, choice2) {
if(choice1 === choice2) {
return "The result is a tie";
}
};
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);*/


#2

I cannot go any farther!


#3

The code for your function is enclosed in a comment. A couple of lessons have us comment out the computerChoice section. Move your compare() function to below the commented section.

/*
...
*/
var compare = function (choice1, choice2) {

};

#4

after I had my thanksgiving turkey dinner with all the trimmings, it all made sense!
I was supposed to leave the commented parts alone and simply type the compare function below the code provided!
so here's all I needed to do to get to work:
/*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);*/ <=== comment ends here!
var compare = function(choice1,choice2) { <=== my code begins here!
if (choice1 === choice2) {
return "The result is a tie!";
}
}; <=== it worked!

my advice based on this is:
if you get stuck, take a break and eat turkey!


#6

this is my answer and it works properly

var userChoice = prompt("rock, paper or scissors?");
console.log("your choice is " + userChoice);

var computerChoice = Math.random();

if (computerChoice <0.34){
    computerChoice ="paper";
}else if( 0.34<computerChoice<0.64){
    computerchoice ="rock";
}else {
    computerChoice = "scissors";
}
console.log("computer choice is " + computerChoice);

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

compare(userChoice,computerChoice);


#8