Why there is 2 parameters

Tell us what’s happening:
i don’t understand the purpose of both parameters.
Also why when i try to console.log my function it doesn’t work

  **Your code so far**
function checkObj(obj,checkProp) {
// Only change code below this line
if (obj.hasOwnProperty(checkProp)){
return obj[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/96.0.4664.45 Safari/537.36

Challenge: Testing Objects for Properties

Link to the challenge:

Hi @s.c.moreno.97 !

Welcome to the forum!

I have added spoiler tags around your code since it is a full working solution.
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 (’).

It looks like you are missing a )
Once you fix that, you should be getting an error message because pet is not defined.

you need to read thoroughly. The parameters are placeholders for arguments to pass into a function to process, just like a tray for foods being passed into a jail-room to be examined by the person in the room. In this particular it gave you two things, and ask you to compare and evaluate whether one has the other within it.

For the console.log. Always check for your typos, misspell, missing syntax (e.g. closing parenthesis, braces, etc). Most of the time a code does not run because of those.

if that’s the case then why would the task know that this would happen

checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift") should return the string pony .

When you call

checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift") ;

Both function arguments have been defined. You have the object {gift: "pony", pet: "kitten", bed: "sleigh"} and the string "gift".

But when you called


above, pet is just some undefined variable.

ok i think i get it so you are actually plugging in that object to the function or “hard coding it” then the second parameter is giving me the value of that property through the actual function

so if i was to plugin

checkObj({city:“Seattle”}, “city”)


i should get seattle ?

because i am leaving out the first parameter

Hard-coding is something different. Hard-coding is when you fix values inside of the function, not when you call the function with a value that only exists for the scope of the current function call.

checkObj({city:“Seattle”}, “city”)


You can’t do this. checkObj takes two arguments. You can’t just remove one for half of your function calls.

1 Like

i think i understand i greatly appreciate everyones time thank you guys !

1 Like

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