Lesson 8 - What if choice1 is scissors? need help!


#1


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


I get error massage that says
Oops, try again. Your code returned 'paper wins' instead of 'undefined' when the inputs are scissors and rock


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

else if(choice1 === "paper") {
}
 if (choice2 === "rock"){ 
     return "paper wins";
}
 else {
        return "scissors wins";
 }
 
if (choice1==="scissors" ){
}
else if (choice2==="rock" ){
    return "rock wins";
}
if (choice2==="paper"){
    return "scissors wins";
}
else {
   return "rock wins";
}
};
console.log(compare(userChoice, computerChoice));


#2

It would seem the second part of the code you did for this lessons just needs to be changed a little. Hope this helps :smiley:

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


#3

nope, New error
SyntaxError: Syntax error


#4

I believe the syntax error is due to your set up of your else if and if statement (The second to last else if statement "if (choice1==="scissors" ){}else if (choice2==="rock" ){return "rock wins";}"). It would seem to be set up backwards so I would correct it by doing this below:

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


#5

All in all I have run this code which I have given in the previous two answers as ways to fix your code and it passes in my lesson assuming your previous lesson work is unchanged. So hopefully that fixes everything
else if(choice1 === "scissors") {
if(choice2 === "rock") {
return "rock wins";
}}
else if(choice1 === "scissors") {
if(choice2 === "paper") {
return "scissors wins";
}
}
}


#6

do you mean I should do it like this

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!";
}
if(choice1 === "rock") {
}

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

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

if (choice1==="scissors" ){
}
else if(choice1 === "scissors") {
}
if(choice2 === "paper") {
return "scissors wins";
}
}
}
else {
return "rock wins";
}
};
console.log(compare(userChoice, computerChoice));


#7

Ok so my whole code is below. In helping you, it is obvious we both have little bit different coding styles for this lesson. So in helping you to pass this lesson I think my coding style has conflicted a little bit with yours. The problems were there but there may have been an easier way to fix it to match the type of coding you were doing. So I am sorry about that and maybe someone a little bit more experienced than I could have done better. It might be worth looking back at some other discussions to find someone's answer which was closer to your original idea. If I can find some I will try and post a link in the discussion.
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 if(choice1 === "paper") {
if(choice2 === "rock") {
return "paper wins";
}}
else if(choice1 === "scissors") {
if(choice2 === "rock") {
return "rock wins";
}}
else if(choice1 === "scissors") {
if(choice2 === "paper") {
return "scissors wins";
}
}
}


#8

1.) https://discuss.codecademy.com/t/unexpected-else-token-8/54038
2.) https://discuss.codecademy.com/t/8-what-if-choice-1-is-scissors/53629
3.) https://discuss.codecademy.com/t/what-if-choice1-is-scissors/53234

all these discussions I think will help if you want your code to be more like your original and in fact the first one has a guy's code whose is very similar to yours at first glance. Hopefully this helps!


#9

Thank for Your help I appreciate it


#10

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