Question for Introduction to Object II Q27


#1

I cannot use bracket notation to store the property's value. Please help me !!!

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

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


#2

You have an object, so you need to get access to property value and print it.

for(var x in languages){
  if(typeof x === "string"){
    var theValue = x[""]
    console.log();
  }
}

What does it mean?
Please clarify what you need to do and where you stuck?


#3

You don't have to store the property's value in a variable in order to print it.
When your if statement accessed the right condition (i.e. if the type is "string"), you can log the value of your property into console. i.e.:

console.log(languages[x]);

p.s. your if condition is accessing the typeof properties in your object instead of values of the keys. That means in this case it will access "english", "french", "notALanguage", "spanish" - which are all strings in fact.

The condition should evaluate the typeof the values not the properties of the object.


#4

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