My code won't work


#1

Hello all, I can't seem to find a problem with my code, but it won't run. FYI I just started coding again, so I won't know any terms. If you just tell me what to do, I'll try to fix it.

var userChoice = prompt("Do you choose rock, paper, scissors lizard, or Spock?");
var computerChoice = Math.random();
if (computerChoice <= 0.2) {
computerChoice = "rock";
} else if(computerChoice <= 0.4) {
computerChoice = "paper";
} else if(computerChoice <= 0.6) {
computerChoice = "scissors";
} else if(computerChoice <= 0.8) {
computerChoice = "lizard";
} else if(computerChoice <= 1.0) {
computerChoice = "Spock";
}
console.log("You: " + userChoice)
console.log("Computer: " + computerChoice);
var compare = function(choice1, choice2) {
if(choice1 === choice2) {
console.log("The result was a tie!")
}
else if(choice1 === "rock") {
if(choice2 === "scissors") {
return "you win"
}
else if(choice2 === "lizard") {
return "you win"
}
else if(choice2 === "paper") {
return "computer wins"
}
else if(choice2 === "Spock") {
return "computer wins"
}
}
else if(choice1 === "paper") {
if(choice2 === "rock") {
return "you win"
}
else if(choice2 === "Spock") {
return "you win"
}
else if(choice2 === "scissors") {
return "computer wins"
}
else if(choice2 === "lizard") {
return "computer wins"
}
}
else if (choice1 === "scissors") {
if(choice2 === "rock") {
return "computer wins"
}
else if(choice2 === "Spock") {
return "computer wins"
}
else if(choice2 === "paper") {
return "you win"
}
else if(choice2 === "lizard") {
return "you win"
}
}
else if (choice1 === "lizard") {
if(choice2 === "rock") {
return "computer wins"
}
else if(choice2 === "scissors") {
return "computer wins"
}
else if(choice2 === "paper") {
return "you win"
}
else if(choice2 === "Spock") {
return "you win"
}
}
else if (choice1 === "Spock") {
if(choice2 === "rock") {
return "you win"
}
else if(choice2 === "scissors") {
return "you win"
}
else if(choice2 === "lizard") {
return "computer wins"
}
else if(choice2 === "paper") {
return "computer wins"
}
}
}
compare(userChoice, computerChoice)


#2

Identifying the issue is a start! And explaining it since you're inviting us to join you.


#3

You can't succeed in chemistry without knowing the periodic table.

You can't succeed in js without the basics. The idea of codecademy is that you will learn to code independently, so maybe you should take a few steps back and make yourself again familiar with the basics of js.

Ability to explain your code is half the solution.


#4

I'm stealing that.