Basic Data Structures - Check if an Object has a Property

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**
let users = {
Alan: {
  age: 27,
  online: true
},
Jeff: {
  age: 32,
  online: true
},
Sarah: {
  age: 48,
  online: true
},
Ryan: {
  age: 19,
  online: true
}
};

function isEveryoneHere(userObj) {
// Only change code below this line
if (userObj.hasOwnProperty('Alan')){
return true;
}
else if (userObj.hasOwnProperty('Jeff')) {
return true;
}
else if (userObj.hasOwnProperty('Sarah')) {
return true;
}
else if (userObj.hasOwnProperty('Ryan')) {
return true;
}
else {
return false;
}
// Only change code above this line
}

console.log(isEveryoneHere(users));

This is not working for some reason. Are we suppose to add our own variables to pass properties outside of the assiend prop in the object in or??

  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36

Challenge: Basic Data Structures - Check if an Object has a Property

Link to the challenge:

Hello there.

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.

Well, I’m using if else if statement to run through each .hasOwnProperty conditions. If the prop exist in the users, it will return true.

Since other prop’s name outside of these 4 properties should return false, outside of these condition is pretty much the -else- statement to return false.

And it’s still wrong.
I did test with console.log(isEveryoneHere('James) and the console gives false log. Still the tests do not accept it.

A return statement immediately stops the function. What will happen in your code if only Alan is ‘online’?

ah, it will still return as true because my if statements only require 1 of the 4 users to be online when I need all four of them to be online at the same time.

So that means I have to write all four userObj into one if statement using &&…can you do thise? (‘Alan’, ‘Jeff’, ‘Sarah’, ‘Ryan’)?

so the if statement wouldn’t be too long.

You can double check MDN and see if hasOwnProperty takes multiple arguments, but probably not:

Yah, the later didn’t work. But I figured it out now thankyou.

I’d like to tell you something off topic. I’ve been getting error page on this forum page using Chrome lately. The page load up, but cannot click or type anything.
But it’s completely fine on firefox.

I did delete all cookies and reset history on Chrome and it was fixed for like a day, now it’s having a problem again.

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