I would like to get a return of false if not all users are present. I have the true part figured out. I know it’s not valid syntax, but that was my last attempt. I really have no idea how to get a return of false.
I’m confused why the first portion of the tests are all marked correct then. The output is true at the bottom. Just can’t figure out what this challenge actually wants, as it doesn’t seem to relate to the actually lesson using .hasOwnProperty or ‘in’ keyword. Again, I know nothing about any of this as a basic beginner, just trying to find a solution to study and understand in order to progress.
the challenge asks you to check an object if it has all four names as properties(and only them). The two methods shown in the lesson are a good way of doing that.
Currently you check if the strings ''Alan", ''Jeff", “Sarah” and “Ryan” return true(which is always the case) and then the entire else block is syntatically invalid(it makes no sense).
Try to log parts of this code in console and see what they output, that way you know if they return what they are designed to
Finish writing the function so that it returns true if the object passed to it contains all four names, Alan , Jeff , Sarah and Ryan and returns false otherwise.
I’ve rewritten your code to the following to help make things more clear. Written this way the problem is broken down into smaller pieces that are easier to solve individually.
function isEveryoneHere(userObj) {
// Only change code below this line
// update the lines
const hasAlan = false
const hasJeff = false
const hasSarah = false
const hasRyan = false
const hasAllNames = hasAlan && hasJeff && hasSarah && hasRyan
if (hasAllNames) {
return true;
}
return false;
// Only change code above this line
}
Tip: Sometimes it helps to write pseudo code before actually writing the real code. That way you can workout the logic without worrying about the syntax.
Not sure why you think that? Your code doesn’t use anything shown in the challenge text.
Did you try using hasOwnProperty or in at all? If so post that code instead.
The parameter userObj is an object, not a function. Using it as a function doesn’t make much sense here. But even if it was a function the value you are passing it just evaluates to false.
I appreciate everyones help and suggestions. Unfortunately, I still can’t figure this one out. Nothing is working correctly. This was my biggest fear of jumping into the coding world and it’s coming true lol. Maybe one day something will click.
The lesson part of the challenge provides excellent guidance on what to do.
See:
const obj={
Alan:1,
Jeff:1
}
console.log('Alan' in obj); //prints true to console
console.log('Alice' in obj); //prints false to console
Now you have a good understanding of &&, but each subcondition needs altering. When you write if ('Alan'), that is not the same as checking if an object has the property of ‘Alan’. And you can tell because you never had to involve the variable name of the object in the if statement, how can the compiler know to check the object for ‘Alan’, if you don’t tell it to in the if statement?
It is completely normal to be overwhelmed by learning programming for the first time.
Just take your time learning and take breaks when things get to crazy.
Then you can revisit it with a fresh perspective and energy to tackle it again.
Please post your current code where you use the techniques shown in the challenge. Even if it is not working. We have to see your attempts.
As said, coding is just hard. You will keep moving the bar up so the problems you are tackling become more and more difficult. No matter how good you get it will always be a challenging, demanding, and at times frustrating process. It is what it is, so get comfortable with it.