I\'m working on a codecademy.com exercise where we use for-in statements to loop through an object and print hello in different languages by checking to see if the values of the
That's because you're checking the key
of the object. To check the actual value, you should be doing something like object[key]
. Try this:
var languages = {
english: "Hello!",
french: "Bonjour!",
notALanguage: 4,
spanish: "Hola!"
};
// print hello in the 3 different languages
for(var hello in languages){
var value = languages[hello];
if (typeof value === "string"){
console.log(value);
}
}