2.1 KiB
2.1 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
567af2437cbaa8c51670a16c | Testing Objects for Properties | 1 | 测试属性的对象 |
Description
.hasOwnProperty(propname)
方法来确定该对象是否具有给定的属性名称。 .hasOwnProperty()
如果找到属性则返回true
或false
。 例 var myObj = {
顶部:“帽子”,
底部:“裤子”
};
myObj.hasOwnProperty( “顶部”); //真的
myObj.hasOwnProperty( “中间”); //假
Instructions
checkObj
以测试myObj
的checkProp
。如果找到该属性,则返回该属性的值。如果没有,请返回"Not Found"
。 Tests
tests:
- text: <code>checkObj("gift")</code>应该返回<code>"pony"</code> 。
testString: 'assert(checkObj("gift") === "pony", "<code>checkObj("gift")</code> should return <code>"pony"</code>.");'
- text: <code>checkObj("pet")</code>应该返回<code>"kitten"</code> 。
testString: 'assert(checkObj("pet") === "kitten", "<code>checkObj("pet")</code> should return <code>"kitten"</code>.");'
- text: <code>checkObj("house")</code>应该返回<code>"Not Found"</code> 。
testString: 'assert(checkObj("house") === "Not Found", "<code>checkObj("house")</code> should return <code>"Not Found"</code>.");'
Challenge Seed
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
// Your Code Here
return "Change Me!";
}
// Test your code by modifying these values
checkObj("gift");
Solution
// solution required