Checking for a property via iteration

Tell us what’s happening:
I’m looking to complete this challenge with a “for … in” loop. However, I’m not sure why the code I wrote doesn’t pass.

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
    for (var prop in obj) {
      if (!obj.hasOwnProperty(prop)) {
        return false;
    return true;
    // change code above this line


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0.

Challenge: Check if an Object has a Property

Link to the challenge:

main issue: if you have return statements in a loop, and one of those will always execute, the loop will stop at first iteration so it’s like it is not there

Next, you are iterating over the properties if the object and then checking if it has the property of current iteration, which, it does because it’s its own already

you need to check if the object has specific properties:

Finish writing this function so that it returns true only if the users object contains all four names, Alan , Jeff , Sarah , and Ryan , as keys, and false otherwise.

You are trying check property on ‘obj’. ‘obj’ doesn’t have properties. You should check property on obj.user.

for(user in obj){
    return false;
return true.

Hope it helps.

that doesn’t seem right
the challenge is asking to check if the object has all four required names, it doesn’t ask about online property

I just showed what was wrong in original code. I didn’t want to post the real answer of the challenge.

what you are saying is not right, obj is an object, user is a string. The loop iterates over the property names of the object in string form.
the goal of the challenge is to check if the passed in object, obj, has the required properties, Alan, Sarah, etc

obj does not have a user property. It does have other properties though.