I cant seem to see the setup information in my initial code?

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

function checkObj(obj, checkProp) {
// Only change code below this line
return "Change Me!";
// 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/97.0.4692.71 Safari/537.36

Challenge: Testing Objects for Properties

Link to the challenge:

Can you describe your issue in greater detail?
The instructions for the challenge are provided in the left side as usual.

If you’re talking about the program not calling the function, its fine since the tests will automatically pass it if the code is correct.

on the left-hand side where the instructions are and on the setup I cant seem to find the examples that they want us to use with the gift, bed, pet stuff.

You can copy and paste the function call from the test to the editor. You’re writing a function that receives an object via arguments, so it needs to work for any arbitrary object passed to it. You don’t need to worry about exactly what objects the tests are passing you (they could be anything).

Oh I see so those are just examples of objects you can put but it doesn’t have to be that specific thing?

The tests call your function. You just need to write the function definition. The object argument is called obj, it’s in the initial code. That, and the checkProp argument, are all you need to reference to solve the problem.

1 Like

The examples and the code on the left is just an example. You will find a very necessary method within though.

If you want to know exactly what is being passed into your function, you can add a console.log(obj,checkProp) line to your code and run it (Ctrl+Enter) to view after you scroll down, passed the tests.

You will find that It passes in an object, and a property name.

Write some code that checks whether the object provided even has the property name given. Return the objects property value if so, otherwise return a string of text that says “Not Found”

It turns out variables and arguments do not favor using them with dot notation, so you will have to use bracket notation to access them.

Ahhh that helps a lot. Let me try to solve the code then and ill get back to you guys if I’m still confused. thanks for the help

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

function checkObj(obj, checkProp) {
// Only change code below this line
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {

if (myObj.hasOwnProperty(checkProp)){
return myObj[checkProp];}

else {return "Not Found";}}

checkObj("pet");
// 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/97.0.4692.71 Safari/537.36

Challenge: Testing Objects for Properties

Link to the challenge:

Why are you declaring myObj inside the function?
The challenge is asking you to complete a function with the parameters obj and checkProp. Any object you’d like to test using the function should be passed as an argument through the parameter obj.

Your code is full of “spelling mistakes” .

First →
Remove the myObj variable.

Second →
Remove the second function in your code. Like it doesnt seem to make much sense.

Third →
In the first function change the obj property to myObj .

Fourth →

remove this . This code block is embedded in your function which is one reason it wont work (Its fine if you delete it from the editor since the fCC editor will pass it)

Even if the code doesnt work after this, check if you have any extra stuff like unwanted brackets and stuff.

If u want to call ur function to see if it works
This part here should not be inside the function, also its incomplete, the function takes two parameters : checkObj(obj, checkProp), one being an object and the other the prop u want check

checkObj("pet");

Yep , and remember to use console.log() so that the result shows in the console

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.


Why are you defining this object?

Why did you redefine the function inside of the function?

It looks like you copy-pasted a part of an answer you found somewhere. What code did you write for this challenge?

2 Likes

Hey yes, I did copy-paste a part of an answer I found from the comment section of the solution part. after my code didn’t work I thought that one of the codes from there would help me understand the task but it didn’t so that’s why I’m asking for help. I erased the code I wrote before so I can’t show it but I’ll attempt to recreate it and make another post on here.

function checkObj(obj, checkProp) {

  // Only change code below this line

  var checkObj; {

gift = "car",

pet = "dog",

bed = "water"

};

function checkObj(checkProp) {

if (obj.hasOwnProperty(checkProp)){

return obj[checkProp];}

else {return "Not Found";}}

  // Only change code above this line

  };

this is what I came up with as a solution but it doesn’t seem to work either I thought I fixed the mistakes mentioned in the other comments but it seems not. Could you please clarify?

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

This is a function definition…

but…

You also defined the same function with a different set of arguments here. That can’t be right.

I see I wasn’t aware of this sort of thing as I don’t usually ask for help. I’ll try to use this next time I ask for help.

No worries. I was just letting you know how/why I edited your post.