Objects Looping though objects

Objects 9. looping through objects.
This is the solution that was given when i hit get solution, however the code does not produce the desired output.

let spaceship = {
    crew: {
    captain: { 
        name: 'Lily', 
        degree: 'Computer Engineering', 
        cheerTeam() { console.log('You got this!') } 
        },
    'chief officer': { 
        name: 'Dan', 
        degree: 'Aerospace Engineering', 
        agree() { console.log('I agree, captain!') } 
        },
    medic: { 
        name: 'Clementine', 
        degree: 'Physics', 
        announce() { console.log(`Jets on!`) } },
    translator: {
        name: 'Shauna', 
        degree: 'Conservation Science', 
        powerFuel() { console.log('The tank is full!') } 
        }
    }
}; 

// Write your code below

for (let crewMember in spaceship.crew) {
  console.log(`${crewMember}: ${spaceship.crew[crewMember].name}`)
};

for (let crewMember in spaceship.crew) {
  console.log(`${spaceship.crew[crewMember].name}: ${spaceship.crew[crewMember].degree}`)
};

//this is the output that is being received

{crewMembers}: {spaceship.crew[crewMembers].name}
{crewMembers}: {spaceship.crew[crewMembers].name}
{crewMembers}: {spaceship.crew[crewMembers].name}
{crewMembers}: {spaceship.crew[crewMembers].name}
//what did produce the correct out put was to not use the ${};

Please resolve this it is very frustrating when it is not printing what was expected.

You forgot the backticks `${someValue}``

console.log(`${crewMember}: ${spaceship.crew[crewMember].name}`)
1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.