Looking for indication to solve this challenge "Check if an Object has a Property"

Tell us what’s happening:
can anyone tell me what’s wrong with my code ?

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
 return obj == obj in users ? true : false;
  // change code above this line


Your browser information:

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

Link to the challenge:

Hi, Prometheus03. Your return statement is incorrect. You are supposed to return what has been assigned to ‘obj’, but you used a comparison operator (==) instead of an assignment operator (=)

Hope this helps.

This is incorrect. The challenge is asking you to return true or false, depending on whether or not everybody is here. obj is just the users object being passed to the function. Also, changing from comparison == to assignment = would change the value of obj, which is not what we want.

Currently, your code is returning either true or false, which is the right idea. The problem is this line: return obj == obj in users ? true : false;

Since we know that obj is just the users object being passed in, your code is essentially saying:

if (users is the same as users in users) {
  return true
} else {
  return false

This doesn’t make much sense, because you are not checking for the right thing. You want to check that the obj being passed is includes the properties Alan, Jeff, Sarah, and Ryan.

I’ll try and let you figure it out from there without giving too much away. If you need it explained a little more in depth, please comment back and I’ll see if I can help.

On a side note, it is almost always better to use ‘strict comparison’ === instead of just ‘comparison’ ==. == can cause some funny problems because it converts data types before comparison. This means that '' == 0 is true, while '' === 0 is false. You can read more about it here.

1 Like

Thanks Lucas. I was focused on the return value and didn’t bother to ask what the challenge was.

No problem, easy mistake to make. One thing I try to do when answering these questions is open up the challenge, copy-paste the asker’s code into the editor, and try to get it to pass the tests from there. That way, you know exactly which part is the problem and how they need to fix it.

1 Like

hi lucas, i changed the condition and it’s all working fine now. thanks