Basic Data Structures - Check if an Object has a Property

Tell us what’s happening:

I was able to get true for both individual “Alan” and array of [‘alan’, ‘jeff’, ‘sarah’, ‘ryan’] but the test is not passing

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
  const type = typeof userObj;
  //console.log(type);
  if (type == 'object'){
  for (let i=0; i<= userObj.length; i++){
    //console.log(true)
  return users.hasOwnProperty(userObj[i])
  } }
  else 
  //console.log('check');
  return users.hasOwnProperty(userObj);
}
  // Only change code above this line


console.log(isEveryoneHere('Alan'))
console.log(isEveryoneHere(['Alan', 'Jeff', 'Sarah', 'Ryan']))

Your browser information:

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

Challenge Information:

Basic Data Structures - Check if an Object has a Property

Welcome back to the forum @This_is_ub

You do not need to use a for loop.
Also, do not access the array directly in the function.

The function needs to pass the users array as an argument.

Happy coding

1 Like