0

I'm writing my first javascript code and when I try to run it, I get the following error

"Uncaught SyntaxError: Unexpected token {"

Why is this happening in this case?

var red = [0, 100, 63];
var orange = [40, 100, 60];
var green = [75, 100, 40];
var blue = [196, 77, 55];
var purple = [280, 50, 60];

var myName = "Manuel";
letterColors = [red, orange, green]
If (15 > 5 ){
bubbleShape = "circle"
}
else{
    bubbleShape = "square"
}

drawName(myName, letterColors);

2 Answers 2

3

If should be if. Remember, Javascript is case-sensitive, and all JS keywords are lower-case.

As an aside...

You are missing a semicolon on several lines, but, as Brad pointed out in the comments, Javascript does not always require semicolons at the end of statements, unless you need to delimit two adjacent statments. In this particular case, the absense of these semicolons isn't causing any errors. That said, it's best to get in the habit of including even non-essential semicolons at the end of your statements to avoid accidentally introducing syntax errors later.

Sign up to request clarification or add additional context in comments.

4 Comments

JavaScript doesn't require a semicolon on the previous line.
True, but it's good practice. That semicolon isn't what is causing your error, but in general it's best to include non-essential semicolons. Thanks for the clarification @Brad
I completely agree, use semicolons... it adds clarity. It's just important to be very accurate in answers, especially to folks new to the language.
Would be good to mention that he doesn't need that if at all... 15 will always be greather than 5.
1
If (15 > 5 ){ //<<< should be if as javascript is case-sensitive
bubbleShape = "circle"
}
else{
    bubbleShape = "square"
}

Working:

var red = [0, 100, 63];
var orange = [40, 100, 60];
var green = [75, 100, 40];
var blue = [196, 77, 55];
var purple = [280, 50, 60];

var myName = "Manuel";
letterColors = [red, orange, green];
if (15 > 5 ){
bubbleShape = "circle";
}
else{
    bubbleShape = "square";
}

drawName(myName, letterColors);

I wouldn't set bubbleShape as a global but pass it as a variable to the function like you do it with your other vars.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.