Tell us what’s happening:
I can’t get my code to pass for the else statements and I keep getting an “Unexpected token” error on my else. I’m not sure what I am doing wrong. Can anyone help me figure out my error(s)?
Your code so far
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh",
city: "Seattle"
};
function checkObj(obj, checkProp) {
// Only change code below this line
if (myObj.hasOwnProperty(checkProp)); {
return myObj[checkProp];
} else {
return "Not Found";}
// Only change code above this line
}
**Your browser information:**
User Agent is: <code>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36</code>.
**Challenge:** Testing Objects for Properties
**Link to the challenge:**
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties
jsdisco I’m not sure. That was the line already included from FreeCodeCamp. But when I remove obj and just have checkProp it makes less of the conditions pass.
function checkObj(myObj, checkProp) {
// Only change code below this line
if (myObj.hasOwnProperty(checkProp)) {
return myObj[checkProp];
} else {
return “Not Found”;}
That might pass the tests, but it’s still a little off - are you aware that you can just delete the object myObj that you’ve created, and the tests will still pass?