I am... once again terrible with syntax


#1

Hi! I decide to go back and take a break for a while and mess around with my rock paper scissors, and I found out if let me go on with a bug! I chose rock, the computer chose paper and it said... scissors win?? So I decided to fix it, but obviously... I got some syntax error... ugh!

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 choice1 = userChoice;
var choice2 = computerChoice;

var compare = function(choice1, choice2) {
if (choice1 === choice2) {
return "The result is a tie!";
} else if (choice1 === "rock" && choice2 === "scissors") {
return "You win!"; 
} else if (choice1 === "paper" && choice2 === "rock") {
return "You win!";
} else if (choice1 === "scissors" && choice2 === "rock") {
return "Computer wins!";
} else if  ( choice1 === "scissors" && choice2 === "paper") { 
return "You win!"; 
} else if ( choice1 === "gun" ) {
return "Gun automatically wins!"
} else if ( choice1 === "paper" && choice2 === "scissors") {
return "Computer wins!
} else if (choice1 === "rock" && choice2 === "paper") {
return "Computer Wins!"
}
};

var userChoice = choice1;
var computerChoice = choice2;
console.log (compare(userChoice, computerChoice));

Yeah... I did a lot...:sweat_smile:


#2

Hi this part

 else if ( choice1 === "paper" && choice2 === "scissors") {
return "Computer wins!
}

you didn't closed the string "