Game runs fine but says "Oops, try again."


#1

So I wrote my game fine and it works great when I run it but the software seems to think I'm messing up... for example if I choose Rock and the computer picks Scissors my output says:

Computer: scissors
"rock wins"

That's all great but the software tells me:

Oops, try again. Your code returned 'paper wins' instead of 'undefined' when the inputs are scissors and rock

Why does it think I'm returning paper wins when it clearly says I returned rock wins?

Thanks


#2

Do you think you could add your code for me? It's most likely just a simple error that you're going to kick yourself over once you find it. But until then the format to add your code in is as follows:

```
<paste code here>
```

Copy those lines into your reply, and then paste your code in the designated area, that will make your code look like:

console.log("I'M SO PRETTY!!");

vs.
console.log("I'm not that pretty :sob:");


#4

Thanks lolman, here's my code. Maybe you can see something that I'm missing. My code is below

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

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

#5

What's the error code you're receiving? I'm sorry for the late response.


#6

For example if I choose rock, and the computer chooses paper, it outputs the right result -- Paper wins but at the bottom it says:

Oops, try again. Your code returned 'paper wins' instead of 'undefined' when the inputs are scissors and rock

I have no idea where it's getting scissors from when neither me nor the computer chose scissors.

See screenshot too.


#7

I looked all up and down this track and I have no clue what's going on. I can only suggest that you refresh your page (or close your browser) then try again.


#8

I have the exact same issue dude.

Heres 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);
console.log("You picked: "+ userChoice);
var compare=function (choice1, choice2)
{
if (choice1===choice2)
{
return "The result is a tie!";
}
else if (choice1 === "rock")
{
if (choice2 === "paper")
{
return "paper wins";
}
else
{
return "rock wins";
}
}
else if (choice1==="paper")
{
if (choice2==="rock")
{
return "paper wins";
}
else {
return "scissors wins";
}
}
else if (choice1="scissors")
{
if(choice2="paper")
{
return "scissors wins"
}
else {
return "rock wins"
}
}
}
compare(userChoice, computerChoice);


#9

it wont let me continue...


#10

I have a similar problem with just one difference. It says "Oops, try again. Your code returned 'scissor wins' instead of 'undefined' when the inputs are scissors and paper".

That's my code!

var userChoice = prompt("Do you choose rock, paper or scissors?");
console.log("User:" +" " + userChoice)
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(choice1 === "paper") {
     if(choice2 === "rock") {
         return "paper wins";
     } else {
         return "scissors wins" ;
     }
 }
 else if(choice1 === "scissors") {
     if (choice2 === "rock") {
         return "rock wins";
     }
     else {
         return "scissor wins" ;
     }
 }
}
compare(userChoice, computerChoice);

EDIT: Just found the mistake. I had written "scissor" instead of "scissors" in the last if/else statement and that was causing the error. Please check for a typo in the strings and you may be find your proboem too!