Im stuck on the rock paper scissors


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


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


you forgot to call the function.

Do you know how to call the function?


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.

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

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


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


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


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


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


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


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