What if choice1 is scissors?


#1

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

I have a Syntax error, but i am not sure my code is right anyway. But immediately i can not look through anymore. can anyone help me?


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 (choice2 === "rock") {
return ("paper wins");    
}

else {
return("scissors wins");
}


else if (choice1 === "scissors") {
    
if (choice2 === "rock"){
return ("rock wins");
}

else {
return ("scissors wins");
}

}    





};
compare(userChoice,computerChoice);


#2

What's the syntax error?


#3

Check the comments above. Then go back to your else if statements for choice1==="rock" and choice1==="scissors". The syntax there is close to being correct. Use them as a guide for your else if choice1==="paper" statement.


#4

Oops, try again. There was a problem with your syntax.

and

SyntaxError: Syntaxfehler


#5

hey thank you for your help, i tried to apply your tips but I do not really get what you mean.
I can not really think through it...
Ich deletet all parantheses for the Returns
I will try to think through it on top of that


#6

Now i could think through it and I get it! Without your Explanation I propably wouldnt have get it :smile:
Because of you I can recognize what the code is for at all! Thank you very much !


#7

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