Tell us what’s happening:
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 names = ["Alan","Jeff","Sarah","Ryan"];
for (let i=0 ; i<names.length ; i++){
if (names[i] in obj){
return true;
}
return false;
};
// change code above this line
}*/
function isEveryoneHere(obj) {
// change code below this line
let names = ["Alan","Jeff","Sarah","Ryan"];
for (let i=0 ; i<names.length ; i++){
return names[i] in obj;
};
// 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/66.0.3359.181 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
These two codes passed the challenge.
I tried to test it on repl.it but the result is always true even I changed the property name.
I think it’s because the return
, which stop the code once it encounters the first true
.
But how can I write it in order to return false if there is no matched property and the whole code will still keep going?