Tell us what’s happening:
I can’t seem to find the mistake in outputting result, I pass on
console.log(checkObj(“gift”));
but it results in NOT FOUND
Your code so far
function checkObj(Obj, checkProp) {
// Only change code below this line
var Obj = {
gift: "pony",
pet: "kitten",
bed: "sleigh",
city: "Seattle"
}
if (Obj.hasOwnProperty(checkProp)) {
return Obj[checkProp];
}
else {
return "Not Found"}
}
// Only change code above this line
console.log(checkObj("gift"))
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36.
Does this look better and i didn’t understand the third point
function checkObj(obj, checkProp) {
// Only change code below this line
// Only change code below this line
var obj = {
gift: "pony",
pet: "kitten",
bed: "sleigh",
city: "Seattle"
}
if (obj.hasOwnProperty(checkProp)) {
return obj[checkProp];
}
else {
return "Not Found"}
}
// Only change code above this line
console.log(checkObj("gift"));
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.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.
You fixed the capitalization of obj, but you are still not using the obj argument.
You should not be creating that object in your code. When the function is called it will be called with two arguments: an object and a string.
Now this creates a problem for the obj and is exactly how it has been explained in the video, i must be wrong somewhere and could you show me the right way
var obj = {
gift: "pony",
pet: "kitten",
bed: "sleigh",
city: "Seattle"
}
function checkObj(checkProp) {
if (obj.hasOwnProperty(checkProp)) {
return obj[checkProp];
}
else {
return "Not Found"}
}
// Only change code above this line
console.log(checkObj("pet"));
I want to do exactly :grinning that but i am having a hard time understanding what you are actually telling me to do, How should i actually output the results of the function where i am being wrong and what is the right way to correct it.