27 Looks for-in to me


#1

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


#2

And your question is?


#3

I think the question is:

"WHAT IS WRONG?"


#4

Also, I need help with this, too.


#5

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]);
}
}


#6

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]);
}
};


#7

@tagrockstar35772
Nah, that can't be it...


#8

if(typeof languages[placeholder] === "string")

here languages[placeholder] should have round brackets like this: if(typeof (languages[placeholder]) === "string")

and it will work.


#12

I solve it in this way

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


#13

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]);
}

}


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

#15

Thanks, works for me!


#16

Refresh your browser


#17

Why is typeof necessary??


#18

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);
}
}


Why doesn't dot notation work with this loop? I wrote the following, but I got an error:
Why doesn't dot notation work with this loop? I wrote the following, but I got an error:
#19

Sorry, but isNaN didn't work for me.:disappointed:
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]);
};
}


#20

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!


#21

I must inform you that it already works.