What's wrong with my code?


#1


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

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

Is there any problem in my code?
I can't find the problem of my code, the console just show nothing when I run this code.


#2

the for in loop stores the properties as string in the loop iterator (property), so you have to use the associative array notation:

languages[property]

#3

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