Check if an Object has a Property (how can I make it work )

Check if an Object has a Property (how can I make it work )
0

#1

Tell us what’s happening:

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) {
  // change code below this line
let regex=/^[Alan,Jeff,Sarah,Ryan]/;
for(users(regex).IndexOf(elem>0){
  return true;
}
return false;
  // change code above this line
}

console.log(isEveryoneHere(users));

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/check-if-an-object-has-a-property


#2

This exercise wants to use method called hasOwnProperty so I wouldn’t use a regex here.

Use this method to check if all the users exist in the object. Return true if they are, return false if otherwise.


#3

yes…but is my code correct ?
I don’t guess so as I’m not sure about the structure


#4

No, it’s not correct.
You probably wanted to use if statement here instead of forloop.
You can’t use regex like that. Use a test method.
It’s indexOf not IndexOf.
You can’t compare if it’s greater than 0 inside your indexof function. You need to get out of it.

Cheers :slight_smile: