I have been stuck in this particular challenge for days

Tell us what’s happening:

  **Your code so far**

function checkObj(obj, checkProp) {
// Only change code below this line
var checkObj =  {

 "gift": "pony",  
"pet": "kitten",
  "bed": "sleigh",
  "city": "Seattle"
 
  
};
if(checkObj.hasOwnProperty(checkProp)) {
  return checkObj[checkProp];
} else {
  return "Not Found";
}

// Only change code above this line
}

  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36.

Challenge: Testing Objects for Properties

Link to the challenge:

Just use obj instead of checkObj they are handing in the object as an argument you do not need to define it. Also you probably do not want to have a variable within a function that shares a name with the function as this can be confusing, and it would make it difficult to reference the function itself within itself should you need to do that.

Can you explain why you thought you needed to define a new object inside of the function?

When this function is called, the arguments are defined and passed in with the names obj and checkProp. You don’t need to make new arguments. Then you code won’t work for a bunch of different objects, which is the whole reason to make functions.

Well, your not the first person to add that object inside the function.

The function signature/definition with its two parameters should make it clear that it takes two arguments when called. However, it would be even more clear if the seed code actually had a call to the function.

Personally, I would much prefer if the seed code always had a call to the function. I think it helps the student quickly connect the definition and usage (without looking at the tests).

I’m not sure if I agree or not.

Some learners develop what I sorta call the ‘peekaboo’ principal about code, where code they can’t see doesn’t exist. This mental model doesn’t work in large applications with code broken across multiple files.

I’m not sure how to teach the idea that a function can exist and be correct without seeing the inputs defined and the function called.

Part of why I asked my first question above is that I’d like to understand where this ‘peekaboo’ misconception comes from.

I get what you are saying and I agree that building up that type of knowledge is important. But I also think what you are talking about comes with experience. Not two weeks into learning JS.


If I want to understand a function I look at:

  1. The base definition (identifier and parameters).

  2. The body.

  3. The call site.

Without seeing the call I would not feel 100% sure I understand how it is being used, especially not with inlined objects as arguments.

That’s fair. I don’t have good sense of what we expect learners to know at this point in the curriculum.

It doesn’t help that this challenge used to have a sample object at one point, and now people seem to find old threads with a sample object and put the sample object inside of the function.

I think your correct that we have old code laying around on the forum that might show up in a search. Not really sure there is much we can do about that.

I’m not sure we can expect anything really. The challenge is about 75% through the starting basic JS challenges. At this point, the student should know how to read a function definition, but they likely also do not yet have enough experience.

We see so many people misreading the functions. Like in challenges where there is a top-level object that is passed in, a lot of people will not use the parameter but the top-level object instead. And that happens even further into the curriculum.

1 Like

I know there are lessons that go into error handling, but I feel like fcc could use more in that department to really drive the point of how important it is to know the best places for logging information. It is pretty often that I see people just not understand where or why a console.log should be used. I agree with @lasjorg that the function should typically be called because while it is important that they understand the functions exist regardless of being called they also won’t be able to see their logs show up in the function unless it’s called.

It may be a bit too coddling to do it for further lessons, and I would probably agree with that, but for the basics of JavaScript I personally don’t think it inhibits their growth more than it inhibits on focusing on things like good logging.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.