Modify tests for testing objects for properties challenge (#38414)
* Stronger test cases for testing objects for properties Change function signature to take in a custom object to be tested * YML formatting mistake * Yaml no space in string * Small one more fix - most likely final * REmove double space in return * Update instruction Section
This commit is contained in:
@ -24,7 +24,7 @@ myObj.hasOwnProperty("middle"); // false
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Modify the function <code>checkObj</code> to test <code>myObj</code> for <code>checkProp</code>. If the property is found, return that property's value. If not, return <code>"Not Found"</code>.
|
||||
Modify the function <code>checkObj</code> to test if an object passed to the function (<code>obj</code>) contains a specific property (<code>checkProp</code>). If the property is found, return that property's value. If not, return <code>"Not Found"</code>.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
@ -32,13 +32,16 @@ Modify the function <code>checkObj</code> to test <code>myObj</code> for <code>c
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>checkObj("gift")</code> should return <code>"pony"</code>.
|
||||
testString: assert(checkObj("gift") === "pony");
|
||||
- text: <code>checkObj("pet")</code> should return <code>"kitten"</code>.
|
||||
testString: assert(checkObj("pet") === "kitten");
|
||||
- text: <code>checkObj("house")</code> should return <code>"Not Found"</code>.
|
||||
testString: assert(checkObj("house") === "Not Found");
|
||||
|
||||
- text: '<code>checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift")</code> should return <code>"pony"</code>.'
|
||||
testString: 'assert(checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift") === "pony");'
|
||||
- text: '<code>checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet")</code> should return <code>"kitten"</code>.'
|
||||
testString: 'assert(checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet") === "kitten");'
|
||||
- text: '<code>checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house")</code> should return <code>"Not Found"</code>.'
|
||||
testString: 'assert(checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house") === "Not Found");'
|
||||
- text: '<code>checkObj({city: "Seattle"}, "city")</code> should return <code>"Seattle"</code>.'
|
||||
testString: 'assert(checkObj({city: "Seattle"}, "city") === "Seattle");'
|
||||
- text: '<code>checkObj({city: "Seattle"}, "district")</code> should return <code>"Not Found"</code>.'
|
||||
testString: 'assert(checkObj({city: "Seattle"}, "district") === "Not Found");'
|
||||
```
|
||||
|
||||
</section>
|
||||
@ -56,13 +59,13 @@ var myObj = {
|
||||
bed: "sleigh"
|
||||
};
|
||||
|
||||
function checkObj(checkProp) {
|
||||
function checkObj(obj, checkProp) {
|
||||
// Only change code below this line
|
||||
return "Change Me!";
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
checkObj("gift");
|
||||
checkObj(myObj, "gift");
|
||||
```
|
||||
|
||||
</div>
|
||||
@ -81,9 +84,9 @@ var myObj = {
|
||||
pet: "kitten",
|
||||
bed: "sleigh"
|
||||
};
|
||||
function checkObj(checkProp) {
|
||||
if(myObj.hasOwnProperty(checkProp)) {
|
||||
return myObj[checkProp];
|
||||
function checkObj(obj, checkProp) {
|
||||
if(obj.hasOwnProperty(checkProp)) {
|
||||
return obj[checkProp];
|
||||
} else {
|
||||
return "Not Found";
|
||||
}
|
||||
|
Reference in New Issue
Block a user