27 Looks for-in to me

for (var x in languages) {
if (typeof(languages)===“string”){
console.log(languages);
}
};

2 Likes

And your question is?

1 Like

I think the question is:

“WHAT IS WRONG?”

3 Likes

Also, I need help with this, too.

1 Like

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

4 Likes

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

21 Likes

@tagrockstar35772
Nah, that can’t be it…

1 Like

if(typeof languages[placeholder] === “string”)

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

and it will work.

1 Like

I solve it in this way

for (var x in languages) {
if (typeof languages === “string”) {
console.log(languages);
} }

4 Likes

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

}

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

Thanks, works for me!

1 Like

Refresh your browser

1 Like

Why is typeof necessary??

1 Like

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

3 Likes

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

1 Like

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!

2 Likes

I must inform you that it already works.

1 Like