Can you help me please? How can I fix this?


#1


I am stuck at building rock, paper, scissors on part 8.
how can I fix it?

it says "Your code returned 'scissors 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!" }
else if(choice1=== "rock")
{if(choice2==="scissors")
{return "rock wins"}
else(choice2==="paper")
{return "paper wins"}}
 else if(choice1==="paper")
 { if(choice2==="rock")
 return "paper wins"}
 else(choice2==="scissors")
 { return "scissors wins"}
  if(choice1==="scissors")
 { if(choice2==="rock")
 {return "rock wins"}
 else(choice2==="paper")
 { return "scissors wins"}}}
 
 compare(userChoice, computerChoice)


#2

if/else syntax

if (condition) {
   //your code
}
else {
    //your code
}

You can see else does not have any conditions associated with it.

Youre writing like this.
wrong syntax

if (condition1) {
   //your code
}
else (condition2){
    //your code
}

which is wrong.
Fix this part,there is one more error to fix.
do reply what you get ?


#3

okay, I fixed that part. Thanks.

what is the other mistake? It still says " Your code returned 'scissors wins' instead of 'undefined' when the inputs are scissors and rock".


#4

You missed curly brackets in last else if statement.
Your if/else is inside else if ? so you need to do like this..

else if (condition) {
    if(condition) {
       //your code
    } else {
       //your code
    }
}

#5

oh, thank you. I fixed it.


#6

cheers! good work! :thumbsup: :slight_smile:


#7

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