for (var x in languages) {
if (typeof(languages)===“string”){
console.log(languages);
}
};
And your question is?
I think the question is:
“WHAT IS WRONG?”
Also, I need help with this, too.
That was my solution:
for(var x in languages){
//declare a variable here receiving the property before the loop. It gets the value of the property, and //checks if it is as string, object or number
var prop = x;
if(typeof languages[prop] === “string”){
console.log(languages[prop]);
}
}
Here’s how I did it, without having to create any additional variables:
var languages = {
english: “Hello!”,
french: “Bonjour!”,
notALanguage: 4,
spanish: “Hola!”
};
// print hello in the 3 different languages
for(placeholder in languages){
if(typeof languages[placeholder] === “string”){
console.log(languages[placeholder]);
}
};
if(typeof languages[placeholder] === “string”)
here languages[placeholder] should have round brackets like this: if(typeof (languages[placeholder]) === “string”)
and it will work.
I solve it in this way
for (var x in languages) {
if (typeof languages === “string”) {
console.log(languages);
} }
isNaN will work too!
var languages = {
english: “Hello!”,
french: “Bonjour!”,
notALanguage: 4,
spanish: “Hola!”
};
// print hello in the 3 different languages
for(var i in languages){
if(isNaN(languages[i])){
console.log(languages[i]);
}
}
for (var x in languages) {
if (typeof languages[x] === "string") {
console.log(languages[x]);
}
}
Thanks, works for me!
Refresh your browser
Why is typeof necessary??
Why doesn’t dot notation work with this loop? I wrote the following, but I got an error:
for (var property in languages) {
if (typeof (languages.property) === “string”) {
console.log(languages.property);
}
}
Sorry, but isNaN didn’t work for me.
This code works for me:
var languages = {
english: “Hello!”,
french: “Bonjour!”,
notALanguage: 4,
spanish: “Hola!”
};
// print hello in the 3 different languages
for (var i in languages){
if (typeof languages[i] === “string”){
console.log(languages[i]);
};
}
RE: Why dot notation doesn’t work… ???
I’d also like an answer to this. Please let me know if you figured it out.
There was something in a previous exercise about the advantage of using rather than .
I clearly didn’t “get” it. If its important then I’d like to.
Not sure how far back it was though…
Thanks in advance to anyone who can help!
I must inform you that it already works.