Basic Javascript no so basic for a Noob

I don´t know what is going on with this challenge, as far as I try once and another ways I cannot pass it, unfortunately this time there is no video to help and in the forum I cannot find a way to do it properly. Could someone help me?

Thanks!

  **Your code so far**

var myObj = {

gift: “pony”,

pet: “kitten”,

bed: “sleigh”,

city: “Seattle”

};

if(myObj.hasOwnProperty(checkProp)==1){

return myObj[checkProp];

}

else{

return “Not Found”;

}

checkObj({pet: “kitten”, bed: “sleigh”}, “gift”);

  **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:

What have you tried already?

You have your function (checkObj) that gets passed and object (obj) and you need to check if this object contains a property (checkProp) that also gets passed to your function.

Your function should:

  1. Check IF the passed object contains the passed property (what can you use to do this?)
  2. IF it contains the passed property the function should return that property value
  3. IF it doesn’t contain the passed property, the function should return “Not Found”

Hope this helps.

I did complete this challenge, the tests were run , got the last line “text completed” and results obtained as in instructions. But, the screen stays there, without taking me to next lesson. I did it on iPad, is it a tech glitch or my code is not correct.

hey @hectoraguirrezabal where’s your code ?

Got it,
The string in else statement was “Not Found!”

“!” Was the error.

Thanks for the reply.

Oh sorry, I missed to put it.
This is so far the best I could do, but still not working depite of it makes sense to me…

Thank you very much.

function checkObj(obj, checkProp) {

// Only change code below this line

var myObj = {

gift: “pony”,

pet: “kitten”,

bed: “sleigh”,

city: “Seattle”

};

if(myObj.hasOwnProperty(checkProp)==1){

return myObj[checkProp];

}

else{

return “Not Found”;

}

checkObj(“Seattle”);

// Only change code above this line

}

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