Code Check, P4 of Rock Paper Scissors


#1


I do not know why I am getting a syntax error. Help.


/*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 win"
            }
        else if (choice1 === "scissors")
        {
            if(choice2 === "paper")
            {
                return "rock wins"
            }else{
                return "scissors wins"
            }
        }
    }
}
console.log(compare(choice1, choice2))


#2

The first two characters onmy this line


#3

I found the error it was a bracket missing, now I just have an error saying Oops, try again. Your code returned 'scissors win' instead of 'undefined' when the inputs are scissors and rock here's my code touched up

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 win"
            }
        }
        else if (choice1 === "scissors") {
            if(choice2 === "paper") {
                return "rock wins"
            }
            else {
                return "scissors wins"
            }
        }
    
}
compare(userChoice, computerChoice)

#4

did you ever get past this code because I'm having trouble with too.


#5

this code is missing semi colons and only prints out the computer choice once once you plug them in.