Step 8: Good morning. Please help me with the right code for this step. Explain to me please where I am going wrong


#1

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


Replace this line with your code. 
var compare = function(choice1, choice2) {
    if(choice1 === choice2) {return "The result is a tie";}
    else if(choice1 === "rock"){
        if(choice2 === "scissors"){
            return "rock wins";
         }// what about if choice2 === "paper"??
    }else if(choice1 === "paper"){
          if(choice2==="rock"){
              return "paper wins";
          }else {
              return "scissors wins";
          }
     }// what about if choice1 === "scissors"??
}else if(choice1 === "scissors"){
          if(choice2==="rock"){
              return "rock wins";
          }else {
              return "scissors wins";
          }
}
}
console.log(compare(userChoice, computerChoice));

I will appreciate. Thanks


#2

else if(choice1 === "paper"){
          if(choice2==="rock"){
              return "paper wins";
          }else {
              return "scissors wins";
          } //closed else
     }  // closed else if 
}  // remove this (you closed the function here)
else if(choice1 === "scissors"){

read my comments


#3

Like this?

var compare = function(choice1, choice2) {
if(choice1 === choice2) {return "The result is a tie";}
else if(choice1 === "rock"){
if(choice2 === "scissors"){
return "rock wins";
}
}// what about if choice2 === "paper"??
else if(choice1 === "paper"){
if(choice2==="rock"){
return "paper wins";
}else {
return "scissors wins";
}
}// what about if choice1 === "scissors"??
else if(choice1 === "scissors"){
if(choice2==="rock"){
return "rock wins";
}else {
return "scissors wins";
}
}
console.log(compare(userChoice, computerChoice));

Still not working.

Sorry, but I think as a new concept, these things have to appear challenging so kindly bear with me. Thanks. But I am much interested in knowing them well.


#4

I have added another } at the very end and it has worked. Thanks much for your assistance. I have appreciated.


#5

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