I created names to iterate in it in order to verify if each name is in the Obj and a ternary conditional to prompt a boolean value, but I don’t know how to check all the hold names at the same time.
//I also tried this solution
for (let i=0; i<names.length; i++) {
return obj.hasOwnProperty == "Alan", "Jeff", "Sarah", "Ryan" ? true : false;
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36 OPR/62.0.3331.119.
note that if you have a return statement inside a loop, the loop will never go past the first iteration!
as soon a return statement is executed the function return a value and stops
now there is something that doesn’t work with the ternary operator!
remember that the ternary operator works like (evaluate this) : (if true do this) ? (else do this), so if “Alan” is there, you are returning true and never checking the others!
function isEveryoneHere(obj) {
// change code below this line
return obj.hasOwnProperty("Alan", "Jeff", "Sarah", "Ryan") ? true : false
// change code above this line
}
Indeed, this solution passed the challenge, despite it doesn’t work:
function isEveryoneHere(obj) {
// change code below this line
return obj.hasOwnProperty("Alan") ? true
: obj.hasOwnProperty("Jeff") ? true
: obj.hasOwnProperty("Sarah") ? true
: obj.hasOwnProperty("Ryan") ? true
: false // change code above this line
}
console.log(isEveryoneHere(users));
they are still both wrong, hasOwnProerty() works with only one argument, all the others are ignored
but I am sure you are almost there, these these things need practice
But I guess that’s not useful because one normally could or could not know the object to evaluate in advance or, in any case, I think is not useful write a function just for one object (users)
Second: doesn’t it suppose to be a function with an argument (Obj) that takes any object and verify if it has determined properties, keys?
Anyways: this last solution produce true if all the names are there and false ONLY if all of them are not in.
The issue is still the same, it is like you are writing users.hasOwnProperty("Alan") because the method takes one argument only, so it ignores the others
it will still give true because it is checking only for the presence of the Alan property
I admit, the tests here are not that well planned, but with a bit of effort you can get the right result!
also, you should always use the function parameter when you are in a function! this is because so the function is reusable
isEveryoneHere(users); // should return true
isEveryoneHere(testObject); // should return false
even if you have the correct code if you don’t use the function parameter inside the function than you will never be able to get different outputs for different inputs