27 looks for-in to me


#1


Why isn't this working what am I doing wrong?


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

// print hello in the 3 different languages
for (prop in languages){
    if (prop == (typeof aString)){
        console.log(languages.prop);
    }
}


#2

You need compare languages prop's values type not prop names:

for (prop in languages){
    if (typeof languages[prop] === 'string'){
        console.log(languages[prop]);
    }
}

UPDATED.

for (prop in languages){
    if (typeof languages[prop] === 'string'){
        console.log(prop + " : " + languages[prop]);
    }
}

#3

this worked thanks,

I feel stupid for asking now I know its so simple :sob:


#4

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