Skip to content

Update testing object #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,39 @@ myObj.hasOwnProperty("top"); // true
myObj.hasOwnProperty("middle"); // false
```

The first ```hasOwnProperty``` returns ```true```, while the second returns ```false```.

## Instructions
- Modify the function `checkObj` to test `myObj` for `checkProp`. If
the property is found, return that property's value. If not, return "Not Found".
- Modify the function `checkObj` to test if an object passed to the function (`obj`) contains a specific property (`checkProp`).
If the property is found, return that property's value. If not, return `"Not Found"`.

### Before

```javascript
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
// Your Code Here

function checkObj(obj, checkProp) {
// Only change code below this line
return "Change Me!";
// Only change code above this line
}

// Test your code by modifying these values
checkObj("gift");
```

### Answers

```javascript
// Setup
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 {

function checkObj(checkProp) {
// Your Code Here
if (myObj.hasOwnProperty(checkProp)) return myObj[checkProp]; // If true return the prop

return "Not Found";
return "Not Found";
}

// Test your code by modifying these values
checkObj("gift");
// Only change code above this line
}
```

### Thinking

Here because the args pass is a string, that mean he have quote. We need
to use bracket notation.
to use bracket notation.