Can the if statement be done on one line?

Tell us what’s happening:

Does it need to be four different (I guess) arguments in the if statement?

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) {
// Only change code below this line
if (users.hasOwnProperty() === 'Alan' && 'Jeff' && 'Sarah' && 'Ryan'){
return true;

}else {
return false
}
// Only 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/85.0.4183.121 Safari/537.36.

Challenge: Check if an Object has a Property

Link to the challenge:

This will not do what you think it does. First, hasOwnProperty must have an argument. Second, hasOwnProperty returns a boolean, not a string name. Third, multiple comparisons don’t quite work like that.

You will need four distinct conditional expressions for this challenge. You can put in all on one line if you like, but you will need a way to express the four separate conditional expressions no matter what. (They are very similar, so there is a way to use high order functions here to reduce duplicate code)

2 Likes

Thank you.

Can you recommend a book or other resources that will allow me to practice more.
I have done most of codecademy as well. I am not doing so well with the algorithms.
Any thoughts on Javascript 30?
My goal is to code an app (in JavaScript so that I can convert it to both android and Ios).