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 JavaScript Loops, Arrays and Objects Tracking Data Using Objects Using `for in` to Loop Through an Object's Properties

The code is not working as shown in the video. Where am I wrong???

here is my code:

var person = {
  name : 'Sarah',
  country : 'US',
  age : 35,
  treehouseStudent : true,
  skills : ['JavaScript', 'HTML', 'CSS']
};

for (prop in person) {
console.log(prop, ": ", person[prop]);
}

can anyone please run this exact same code and see where it's wrong??

7 Answers

Alexys Louis
Alexys Louis
5,260 Points

Where you have:

for (prop in person) {
console.log(prop, ': ', person[prop]);
}

make sure you're including 'var' before prop.

for (var prop in person) {

}

Hope that helps.

Dario Bahena
Dario Bahena
10,697 Points

Your code is fine. Reload your browser. Something else is wrong other than your code essentially.

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

I'd like to add that it might be a good idea to check some basics. Make sure you've saved the file. If there's an orange dot on the tab, it hasn't been saved. If it has been successfully saved, you might try clearing your browser cache. There's always the chance that it's loading in an older version of your code. Hope this helps! :sparkles:

if you notice it in the console, it's showing this: skills : Array(3);

but in the video, it showed all the skills in the array.... you can review the video {to the last part only, where he opens up the browser console...}

Thanks, Alexys, you're a lifesaver, can you kindly explain why this works the way it does?

Alexys Louis
Alexys Louis
5,260 Points

I'm glad I could help.

Remember that 'prop' is a new variable being introduced to the code, so you do have to label it has a variable. I hope that's a good explanation.

This code is correct check if the error is not come from another part

I recommend to use chrome, it'q better to find the errors