Why is not it working?! "What if choice1 is scissors?"


#1

Help me!

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 === "rock") {
    return "rock wins"
}
else {
    return "scissors wins"
}
}
}
console.log (compare(userChoice,computerChoice))

#2

I really do not know what to do!


#3

the problems seem to be in this section:

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

first of all, this line:

if (choice2 ==="rock")

where is the opening curly bracket ({)?
Now, your else if(choice1 === "paper") { doesn't have a matching closing curly bracket, add one before your else if (choice1 === "scissors")


#4

I added and yet it gives me the message ERROR:

SyntaxError: Unexpected token else

you see something?


#5

Well, you changed something so i need to see an updated version of your code


#6
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 === "rock") {
    return "rock wins"
}
else {
    return "scissors wins"
}
}
}
console.log (compare(userChoice,computerChoice))

#7

You seem to have forgot step 2 of my instructions:

else if(choice1 === "paper") { <- the opening curly bracket there doesn't have a matching closing curly bracket, after the else.


#8

It works!
** thank you very very much!!!!**