Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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]);