Checking to see if property exist

Tell us what’s happening:
so my if statement is suppose to return true if the property exist in object and false if it does not exist
my second if statement is not working please tell me whats going on.

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 counter = 0;
    for (let user in obj) {
       
        if(obj[user].online === true){
            counter ++;
            return true
            if (!obj[user].online) {
              return false
            }
        }
    }
    return counter;
    
  // change code above this line
}

console.log(isEveryoneHere(users));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) 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

You are looping through an object.

The first thing you are doing is checking to see if a first user in the object has status of online === true. If it’s yet, then you are returning true to get out of the loop and the function.

So I wouldn’t put return true right after your first check. I would only return true after your condition meets your requirements. I also wouldn’t put another if statement in the same block as your if statement after return true, because it will never be executed.

I misinterpreted between the if value of true or checking the value exist within the object.