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

Emma Winston
Emma Winston
1,154 Points

Intro to Programming 'objects' lesson - updating object as per video gives me a syntax error!

Hi,

I'm working my way through Introduction to Programming and despite following along with Jim's code exactly, I'm getting a syntax error when I try to update one of the values stored in an object.

The code is as follows:

var me = {
    first_name: "Jim",
    last_name: "Hoskins",
    "Employee Number": 1
}

me.first_name: "James"

console.log(me.first_name);
console.log(me.last_name);
console.log(me["Employee Number"]);
console.log(me)

var key = "first_name";

console.log(me[key]);

In the video, this updates Jim's name in the console to 'James', but when I do it all I get is

SyntaxError: missing ; before statement
me.first_name: "James"

All I can think is that I've made a typo or something, but I can't find it. :/ Can anyone help?

1 Answer

I think you're missing a few semicolons to close your lines. One is after your closing curly bracket on your first set of variables, and then on a few other lines.

var me = {
    first_name: "Jim",
    last_name: "Hoskins",
    "Employee Number": 1
}; // First

me.first_name: "James"; // Second one

console.log(me.first_name);
console.log(me.last_name);
console.log(me["Employee Number"]);
console.log(me); // And third. Easy to miss!

var key = "first_name";

console.log(me[key]);