#7 Help needed


#1


Hi friends.

Disappointed with myself. I have followed the instructions and check some post in this forum but I still doing something wrong.

Someone can help?
Code and error's messages copied below.

Thanks


https://www.codecademy.com/en/courses/javascript-beginner-en-Bthev-mskY8/1/3?curriculum_id=506324b3a7dffd00020bf661


Oops, try again. There was a problem with your syntax.

SyntaxError: Unexpected token else


/*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 (computerChoice, userChoice) {
    if (computerChoice === userChoice) {
    return "The result is a tie!";
    }
    
    else if(computerChoice === "rock") {
        if (userChoice === "scissors") {
        return "rock wins";}
        }
        else{
        return "paper wins";}
}
    else if(computerChoice === "paper"){
        if (userChoice === "rock"){
        return "paper wins";}
    }
        }else{
        return "scissors wins";}
        }
        };


#2

The 2 curly brackets before your else aren't needed here. Also, be sure to close your compare function with the correct syntax.


#3

Thanks, thanks, thanks!!!

Actualy I had 3 curly brackets not needed in my code.

Do you know links with sintax lessons for beginners? I "need" more background to understand the basic sintaxis rules.

Thanks again for your help biff75


#4

Anytime :slight_smile:

Try going over this:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript

I learned a lot by reading answers to posts on this forum though.


#5

Thanks again biff :slight_smile:

You are very helpful. Looks like a very interesting guide..


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.