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

Not sure what's wrong. Keeps saying to make sure let us in the for in loop

script.js
const composer = {
  name: 'Edward Ellington',
  nickname: 'Duke',
  genres: ['jazz', 'swing'],
  instrument: 'piano'
};

for(let key in composer){
  console.log(key);
}

for (let prop in composer) {
  console.log( `${prop}: ${composer[prop]}`);

In the final console.log, you missing the + before composer.prop:

console.log(prop, ': ' + composer.prop);

Michael Kobela I made a mistake and had an old clipboard copy pasted in the code. See the new change.

It keeps saying β€œbe sure to use let in the for loop” obviously it’s there.

From what I see your for loop is missing the closing } :

for (let prop in composer) {
  console.log( `${prop}: ${composer[prop]}`);
}

1 Answer

Martin Sole
Martin Sole
82,199 Points

Hi

You have the correct answer in your code, but your answer just needs tweaking. The the second part of the challenge is asking you to also include the values as well as the property names, which you have correctly done, but it wants you to add this to the for loop created in the first step rather than creating a second a for loop.

Thanks, that worked. They should've said to replace the previous rather than what it asked.