Tell us what’s happening:
I am not sure why my code doesn’t return true when the condition is true. Can someone explain to me why this code doesn’t work properly? I was thinking that if all of the names are in the object, then the function would return true, if not, then the function should return false.
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
obj = users;
if ('Alan'&&'Jeff'&&'Sarah'&&'Ryan' in obj === true){
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/81.0.4044.138 Safari/537.36.
and all conditions are independent from each other.
so, looking at your code, condition1 is just "Alan", which doesn’t check anything. your code is just checking if "Ryan" is a property of the object
Sometimes I am confused because the code never declares that the variable obj is referring to the users object. Can we use variables in a function without defining them?
oh that makes sense. I went back and tried another way to see if I could use the ‘in’ function, but it still didn’t work. Does’t this now say if all of the strings are in the object, then it would return true?
if ((‘Ryan’&&‘Sarah’&&‘Jeff’&&‘Alan’) in obj