Last step "Rock, Paper, Scissors" - Syntax Error


#1

Please help me find the syntax error(s) : :cold_sweat:
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 wins";
    }
}
else(choice1 === "scissors"){

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

};

compare(userChoice, computerChoice);


#3

There are a few problems with this code:

First you don't need to rewrite Math.random. It is a built-in method that just needs to be called so no need to wrap the stuff after this is {}.

And the other thing is about else:

else(choice1 === "scissors"){

else has no condition attached to it, if you need a condition use else if and if not just use else and get rid of the condition this occurs twice in the last segment of your code.

@trabajador Pls do not post solutions. These exercises are doable and if they are not mention your problem with them but don't post solutions. Also if you post code please format it so that it is easier to read and give some explanation on what you changed and what was the actual problem, because as these exercises are rather short the codes look all pretty similar even if they are not...


#4

Thanks!
I didn't realize "else" alone does not take a condition or that Math.random() just needed to be called. You've been very helpful! I was stuck at this syntax issue for a long time. :rabbit: