Initial code is incomplete

Tell us what’s happening:
There is something wrong with the exercise below; this was all that was given to me to complete this lesson, " Basic JavaScript: Testing Objects for Properties." When I look through the Help/Video and the forum, there was more initial code to it to complete the exercise. Please fix.

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/80.0.3987.149 Safari/537.36.

Challenge: Testing Objects for Properties

Link to the challenge:

The code is good. This was changed very recently and the video might not be up to date. But you can do this without the video. The function checkObj is getting two parameters passed into it:

obj: an object
checkProp: as string representing the property you want to check in the object

So you just need to complete the function body to do as the instructions say.

Strange, this is my solution:
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
}

But it doesn’t work through the tests. The initial code in the video is different. Have the testing scripts been changed too?

Just for future reference, whenever you paste code in a comment you need to put triple back ticks (the key in the upper left of your keyboard, just below Esc) before the code and then after the code. That will allow it to format properly in the comments.

Remember, the parameter checkProp is a variable that contains a string. How do you access the value that checkProp is holding?

Thanks bbsmooth! Nevermind! Sorry! I tested this in a console and I realized in my conditional statement that I was mistakenly looking for property name called “checkProp” but I should be testing for checkProp (the variable). Thanks again for your patience! Thanks for the “triple back ticks” tip!