Im stuck on the rock paper scissors


#1

I cant seem to make it give me the result of the game :C am i missing something?
below is 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 === "paper"){
    if (choice2 === "rock"){
    return "paper wins";
}
else {
    return "scissors wins";
}
}
else if (choice1 === "scissors"){
    if (choice2 === "rock");
    return "rock wins";
}
else {
    return "paper wins";
}
}
console.log(compare)

#2

Check your code for spelling errors and if your compare function syntax is correct.


#3

you forgot to call the function.

Do you know how to call the function?

https://discuss.codecademy.com/t/i-do-not-understand-how-to-call-a-function-what-am-i-doing-wrong/37701/7?u=rcodeman


#4

@holykitty,
-1
For the Javascript interpreter, a semi-colon-; is an End-of-Statement indicator
and if you use

if (choice2 === "rock");

that would be interpreted as an END of IF statement.

-2
Also the a code-block should be encapsulated in a pair of curly-brackets-{ }

-3
If you want to execute the compare function
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 )

#5

yes thank you i forgot to put in (choice1,choice2) after compare it works now.


#6

thank you i corrected it as i was reading the page of my question. i appriciate your answer.


#7

i found a line i wrote choise instead of choice and corrected the part for calling the function. thank you for the answer.


#8

@holykitty,
The argument's to be used are userChoice and computerChoice
like
console.log( compare( userChoice,computerChoice ) );


#9

yes.i choose to write console.log(compare(choice1,choice2)) this form also worked.


#10

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