我不确定为什么我的代码不起作用

时间:2016-05-12 11:42:35

标签: javascript

我遇到了一个任务问题。如何使我的代码工作?

var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
  if (myObj.hasOwnProperty(checkObj) === true) {
return  myObj[checkObj];
} else return "Not Found";
}
myObj.hasOwnProperty(""); 
// Test your code by modifying these values
checkObj("gift");

1 个答案:

答案 0 :(得分:3)

检查您的变量名称

var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here       vv HERE vv
  if (myObj.hasOwnProperty(checkProp) === true) {
return  myObj[checkProp];  // <= and here
} else return "Not Found";
}
myObj.hasOwnProperty(""); 
// Test your code by modifying these values
checkObj("gift");