Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Uncaught syntax error: Unexpected token [

I'm on the objects stage (Stage 6) of JavaScript, and my Google browser's console ran fine until using jim.["favorite color"] object. I compared the code Jim typed in the video with mine and still can't find what I did wrong.

//Java Script Objects

var jim = { 
    name: "Jim", 
    skills: ["JavaScript", "Ruby", "Dancing"],
    "favorite color": "green"
};

jim["favorite color"] = "blue";

console.log(jim.["name"]);
console.log(jim.["favorite color"]);

2 Answers

Kevin Kenger
Kevin Kenger
32,834 Points

Hey nikoxyz,

It looks like you're using both the dot notation as well as the bracket notation to log the properties of Jim. Try removing the period between Jim and the brackets.

console.log(jim["name"]);
console.log(jim["favorite color"]);

Thank you! I'll watch out for the periods next time.