Tell us what’s happening:
I think I have found a valid solution for the challenge “Check if an Object has a Property”, but the tests fail. Could someone comment if my solution is wrong and why or if the tests didn’t evaluate my solution correctly?
My 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
for (let name in obj) {
if (!(name in users)) {
console.log(name + " is false.")
return false;
} else {
console.log(name + " is true.")
}
}
return true;
// Only change code above this line
}
console.log(isEveryoneHere(users));
(I have added some console.log statements to check if I got the correct branch of the if statement.
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.152 Safari/537.36
.
Challenge: Check if an Object has a Property
Link to the challenge: