2.8 Build rock paper scissors - What am I doing wrong?!?!


#1

The exact exercise I'm stuck on is 8.What if choice 1 was scissors and the link to it is here:
https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/4?curriculum_id=506324b3a7dffd00020bf661

Every time I click submit I get a syntax error and I can't see what the problem is. I was wondering whether anyone here could give some quick tips on how to get this code working? I've tried several things, but nothing seems to quite do the trick. There may be more than one error because I've tried to edit my previous code as well thinking that it was perhaps an error with the answer whatever checking mechanism CodeAcademy uses :slight_smile:


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

compare(userChoice,computerChoice);


#2

You have an extra closing bracket } before the last else if statment.


#3

Cheers! I saw that response to a similar question about this exercise so many times and I could have sworn that I had the right amount of brackets. Great help, thanks! :slight_smile:


#4

var userChoice = prompt ("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
console.log(computerChoice);

if (computerChoice <= 0.33) {
console.log("rock");
} else if (computerChoice >= 0.34 <=0.66 ){
console.log("paper");
} else {
console.log("scissors");
}