What if Choice 1 is rock


#1


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

problem with syntax

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("User: " + userChoice);*/

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";
    }     
}
};
    }
    
};


#2

HI first close your if statement and you have more } than you need you should remove some and

Hint

#exactly 2 }

Then close the comment /* */


#3

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("User: " + userChoice);*/

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";
}
}

removed } and closed if..but still problem with code


#4

YOu should remove two } instead of three.


#5

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("User: " + userChoice);*/

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";
}
}
};

is this correct? confused..please help


#6

And you should close the /* */ Because you should put it as a comment

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("User: " + userChoice);*/

work like that...

/*

I'm a comment

*/

#7

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("User: " + userChoice);*/

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";
}
//

}

can you please check above line..showing. commented part I have additionally added


#8

All your else if statement should be inside the compare function

var compare = function() {#open the compare function

#here put all the else if statement

}#close the compare function

then here

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

since it's the last else if statement you should add one } for clossing the compare function and you also forgot to open the if statement {