Don't understand what to do in "Basic Data Structures: Check if an Object has a Property"

Tell us what’s happening:
I tried to copy the example, but it was something else I had to do.

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(obj) {
// Only change code below this line
if (obj in users | users.hasOwnProperty(obj)) {
return true;
}  
return false;

// Only change code above this line
}

console.log(isEveryoneHere(users));

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0.

Challenge: Check if an Object has a Property

Link to the challenge:

Users is the object. You should be using obj as the users object.

1 Like

Also, note that | and || is not the same thing.


1 Like
obj.hasOwnProperty(users)

I need to do square brackets or dot?

The names of people are your properties

1 Like

obj and users is the same thing. The challenge is passing the users object as obj parameter to the isEveryoneHere(obj) method so your condition is wrong. You have to check for every property individually like this

if ('Alan' in obj && "Jeff" in obj && "Sarah" in obj && "Ryan" in obj){
    return true
  }
   else{
    return false
  }

Try printing out obj also to see what inside it.

1 Like

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.
If you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

2 Likes

Ok I will keep that in mind next time. Thanks.

1 Like

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