Tell us what’s happening:
Describe your issue in detail here.
Your code so far
why my code won’t pass this challenge? what did I do wrong?
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 (users.hasOwnProperty(userObj)){
return true;
} else {
return false;
}
// Only change code above this line
}
console.log(isEveryoneHere(users));
Your browser information:
User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 16_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Mobile/15E148 Safari/604.1
Challenge: Basic Data Structures - Check if an Object has a Property
The directions ask you to
" Finish writing the function so that it returns true if the object passed to it contains all four names, Alan , Jeff , Sarah and Ryan and returns false otherwise."
With your code you are not checking to see if the object has all four names. hasOwnProperty checks to see if the object has a specified property, but you are not passing a property from the object in to check. You are passing in the object again which doesnt works. To put it another way the challenge is looking for
obj.hasOwnProperty(property)
but what you are giving the function is
obj.hasOwnProperty(obj)
So, first thing is you need to change the code so the function is passing a property and not the object. Second, you need to make sure you are checking the object for all four names.