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 Objects Loop Through Objects Loop Through an Object's Properties

The console should display four lines that include both the property name and value. For example: 'instrument: piano'.

script.js
const composer = {
  name: 'Edward Ellington',
  nickname: 'Duke',
  genres: ['jazz', 'swing'],
  instrument: 'piano'
};
for(let prop in composer)
  console.log(prop)
console.log(`${prop}: ${composer[prop]} `)

1 Answer

Dane Parchment
MOD
Dane Parchment
Treehouse Moderator 11,077 Points

The issue here is syntax (depending on if Treehouse is using strict syntax in their editor) and the fact that you are leaving the previous solution there, as well as the extra added space in your solution.

So one issue at a time:

  1. Syntax, make sure your for..in loop has brackets
for(let prop in composer) {
}
  1. Remove the previous solution, you should only be logging what they are asking you to log which is now, the property and value.
for(let prop in composer) {
    console.log(`${prop}: ${composer[prop]}`);
}
  1. You added a space at the end of the ${composer[prop]} like that. Remove it, Treehouse's solutions tend to be very specific about the syntax of the solution.