Check if an Object has a Property!

Check if an Object has a Property!
0

#1

Tell us what’s happening:
I already passed the test using ‘in’ keyword instead, but I just wanted to make sure that it is not a bug in the website and I did it right. Thank You. :slight_smile:

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
if ('Alan', 'Jeff', 'Sarah', 'Ryan' in users ){

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

Hey @AndrewAlkazeer,
You are not using the arguments inside your function anywhere in your code.
Think about where you will fit in it and then try solving.
Hope that helps.


#3

In addition to what @aditya_p said (which involves changing just one specific thing in your code), this:

if ('Alan', 'Jeff', 'Sarah', 'Ryan' in users )

Is not valid syntax and will cause an error. a in y && b in y && c in y not a, b, c in y


#4

I fixed it, it worked now. Thank You :slight_smile:

function isEveryoneHere(obj) {
  // change code below this line
if (obj in users ){

return true;
}
return false;
  // change code above this line
}

console.log(isEveryoneHere('Jeff'));

#5

The code you posted above should not pass the 2nd test. I tested the function above myself and it does not pass for me. If you passed the test, can you post the entire code?


#6

Sure. Here we go:

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
if (obj in users ){

return true;
}
return false;
  // change code above this line
}

console.log(isEveryoneHere('Jeff'));

You are right! I tried it too now and it did not pass the second test either, I do not know how I passed then, but if you check repl.it it will work :face_with_raised_eyebrow::face_with_raised_eyebrow:

Here is the link on repl.it : https://repl.it/@AndrewAlkazeer/AuthenticCrispWearables-28


#7

Your function returns true only because you are passing in a string (one of the names in the users object).

The default code in the challenge has the following console.log statement. If you would not have changed the argument value then you would see false returned in your repl.it

console.log(isEveryoneHere(users));

See how the users object is being pass instead of a string?