Anyone has a good explanation why we can’t use the dot notation instead of the bracket notation on the last line of this code to console log the crew Member’s name?
console.log(
${crewMember}: ${spaceship.crew.crewMember.name});
instead of:
console.log(
${crewMember}: ${spaceship.crew[crewMember].name});
I can’t see the reason why not.
let spaceship = {
crew: {
captain: {
name: 'Lily',
degree: 'Computer Engineering',
},
'chief officer': {
name: 'Dan',
degree: 'Aerospace Engineering',
},
medic: {
name: 'Clementine',
degree: 'Physics',
translator: {
name: 'Shauna',
degree: 'Conservation Science',
}
}
};
for (let crewMember in spaceship.crew)
console.log(`${crewMember}: ${spaceship.crew[crewMember].name}`)