27. Looks for-in to me


#1

Hi,

https://www.codecademy.com/courses/objects-ii/5/1?curriculum_id=506324b3a7dffd00020bf661#

I am trying to get this done and looked at example from another thread, but this does not work.
It says: "Oops, try again. It looks like you didn't print Hello!" And in the black box it reads: "undefined undefined undefined". What is wrong with this?

var languages = {
    english: "Hello!",
    french: "Bonjour!",
    notALanguage: 4,
    spanish: "Hola!"
};

// print hello in the 3 different languages
for (var key in languages) {
    if (typeof languages[key] === "string") {
        console.log(languages.key);
}
}

#2

Hey @mariamariiia it looks like you're using both [bracket]notation as well as dot.notation in your code..

Try using bracket[notation] within all parts of your for loop :smiley:

Let me know if you need further prompting :slight_smile:


#3

#4

I got it right now and it printed everything right, but why it has to be languages[key] and not languages.key?


#5

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