You’re not really doing what it’s asking you.You need to create an if loop, that uses the .hasOwnProperty to check if the names are part of the obj that is passed in. (the obj is the users object WITH the names in your code editor.) You’re basic structure is supposed to look like
if(true){
return true;
}else{
return false;
}
where the first ‘true’ condition is the bool variable from obj.hasOwnProperty will give you when you check the names.
you cannot return obj in users, because the in operator is used for iteration (looping)
the syntax you want is for 'var' in 'obj'
the for starts the loop
‘var’ is the name you assign to the current property in the object
obj is the object you are iterating over (looping over)
Since the var variable is the name you assign for the property key during iteration, you can’t place the parameter (obj in this case) there. It should be switched with users
Pleae check my solution.
I have made the array of the uers and for looped it . It works for me
function isEveryoneHere(obj) {
let members = [ 'Alan', 'Jeff', 'Sarah', 'Ryan'];
for (let i = 0; i < members.length; i++) {
return obj.hasOwnProperty(members[i])
}
}
function isEveryoneHere(obj) {
// change code below this line
return 'Alan' in obj && 'Jeff' in obj && 'Sarah' in obj && 'Ryan' in obj;
// change code above this line
}
Your solution is incorrect as the criteria is that all users must be in the object.
The test suite must be wrong as your solution evaluate true in any cases. No matter if the user in the object or not.
It is quite troublesome when one doesn’t read the question. Took me some time to realize it. =(
The function has to check if the passed argument, users, contains the names: Alan, Jeff, Sarah and Ryan. And only returns true if the four names are in obj.
A loop to check each name, accumulated in an array, to verify it exists in obj is fine
here is my function but saw a very nice and shorter alternative before.
function isEveryoneHere(obj) {
let names = ["Alan", "Jeff", "Sarah", "Ryan"];
let ok = 0;
for (let name of names) {
if (name in obj) {
ok++;
} else {
return false;
}
}
if (ok === 4) return true;
}
Hey guys, quick question, the hint solution uses commas (,) instead of the “and” operator in the if statement, but I found out that even if you add more properties afetr the commas that are not in the object, it still evaluates to true. Is my solution below (it passed the test) the best way or am I missing something?
function isEveryoneHere(obj) {
if (obj.hasOwnProperty(‘Alan’ && “Sarah” && “Jeff” && “Ryan”)) {
return true;
}
return false;
}
let list = ['Alan', 'Jeff', 'Sarah', 'Ryan']; // create array with names
function isEveryoneHere(obj) {
let arr = []; // declarate empty array
for (var i = 0; i < list.length; i++)
{
arr.push(obj.hasOwnProperty(list[i])); // push all booleans in the arr
}
let sum = arr.reduce((a, b) => a + b, 0); // find sum of arr: true (1), false (0)
if (sum !== list.length) { //compare arr sum and list length
return false
} else {
return true
}
function isEveryoneHere(obj) {
// change code below this line
let check = 0;
for(let user in obj){
if(user in obj){
check++;
}
}
return (check == 4) ? true : false;
// change code above this line
}
I don’t se how, you are just checking if the object has his own properties - which will return true or false in the way this challenge expect, but it is not what the challenge actually asks from you
As much as this pass tests (and please blurry full.working solutions!), these are wrong
Both the in operator and the hasOwnProperty method accept one argument only
Challenge is being changed so that this is considered, with next curriculum update tests will make sure this will not work