Couldn't get past level 8


#1


https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/4?curriculum_id=506324b3a7dffd00020bf661#


Hello! In the 8th level of rock,paper,scissors game, I couldn't proceed because I'm stuck at the final calling of compare function. I am writing either "rock, paper or scissors" in the two arguments but it is still showing error as shown in the above link or in the code below. Please help me out. Thank you.


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==="paper") {
        if(choice2==="rock") {
            return "paper wins";
        }
        else {
            return "scissors wins";
        }
    }
    else if(choice1==="scissors") {
        if(choice2==="rock") {
            return "rock wins";
        }
        else {
            return "scissors wins";
        }
    }
};
compare("rock","paper");


#2

here:

compare("rock","paper");

even when user pick scissors, and the computer picks rock, your function is still going to run rock for user, and and paper for computer even though user and computer didn't pick this options

use the variable which contain user choice and computer choice


#3

That's what the error is saying too! but i don't understand the meaning of "use the variable which contain user choice and computer choice". If i am writing userChoice() and computerChoice() at the end of the code instead of compare(), it's still giving error. So how can I proceed?


#4

userChoice and computerChoice should be the arguments when calling the compare function, not "rock" and "paper", because then what the user and computer chose is irrelevant.


#5

Oh yeah I understand now. It's working finally. Thanks alot!


#6

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