8. what if choice1 rock


#1

you know in lesson 8 I had all right but I get error massge that says
Oops, try again. Your code returned 'paper wins' instead of 'undefined' when the inputs are scissors and rock

here is 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);
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 "paper wins";
}
};
console.log(compare(userChoice, computerChoice));


Lesson 7:What if choice1 is paper?
#2

It's better if you make a new post for different lessons, that way other people can follow what is happening.

There are two places in your code where you have set the condition but then omitted the code to be executed.

if (condition) {
Say what happens if the condition is met.
}

#3

Like @astrophe717 mentions, you need to work on your if statement and else if statement code blocks. If I were you, I would go back to the instructions, read the hints and closely examine the code for a nested if/else statement inside of an else if statement. You may need to rewrite the entire compare function.


#4

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