Looks For-In To Me


#1


https://www.codecademy.com/en/courses/objects-ii/5/1


???
???
???
???


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

// print hello in the 3 different languages
for (var x in languages) {
    if (typeof languages.x === "String") {
        console.log(languages.x);
    }
    else {
        console.log("???");
    }
}

I can't print out the type.. it says 'undefined'.


#2

the for in loop stores the properties of object as string, so you have to use associative array notation (square brackets)

also, typeof will return "string" and that doesn't equal "String" (comparison is case sensitive)


#3

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