However, when I run it, Repl.it spits back the following error:
/home/runner/NutritiousNanoFeed/index.js:3
gift: “pony”,
SyntaxError: Invalid or unexpected token
The code was correct in the challenge, but I always want to try it in Repl.it to see it go. Can anyone please help me understand the error code and how I made a mistake in actually running this code in Repl.it? – Much appreciated!
//Code so far:
var myObj = {
gift: “pony”,
pet: “kitten”,
bed: “sleigh”
};
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
}
// Test your code by modifying these values
checkObj(“gift”);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36.
Randell, fixing the quotes fixed the issue. But I left the object before the function and it worked. Where would be the better location? This is an important thing I don’t think I am understanding. I know the object must be defined but I’m still fumbling around with placement of them in the code.
Thank you again for your time.
inside the brackets or checkObj(“gift”); would not know where to look. Am I correct that you are saying it should be placed after the
return “Not Found”;
}
This is not needed as it is never used. Each test passes a different object (the first argument) and the property to look for (the second argument) to the function. Your function should be able to handle any object and property passed to it and return either the value of the property (if found) or the string “Not Found”. For example, if your function is written correctly, I should be able to make the following call to it: