Skip to content

Commit

Permalink
Merge pull request #266 from benjibuiltit/object-keys
Browse files Browse the repository at this point in the history
added object keys challenge
  • Loading branch information
ledsun committed Aug 17, 2019
2 parents 1cc7f3b + 5cdb63a commit 62945d2
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 6 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ Code contributions welcome! Please check our [documentation on contributing](htt

Add these challenges:

- "OBJECT KEYS"
- "FUNCTION RETURN VALUES"
- "THIS"

Expand Down
1 change: 1 addition & 0 deletions menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"LOOPING THROUGH ARRAYS",
"OBJECTS",
"OBJECT PROPERTIES",
"OBJECT KEYS",
"FUNCTIONS",
"FUNCTION ARGUMENTS",
"SCOPE"
Expand Down
45 changes: 42 additions & 3 deletions problems/object-keys/problem.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
---
JavaScript provides a native way of listing all the available keys of an object. This can be helpful for looping through all the properties of an object and manipulating their values accordingly.

#
Here's an example of listing all object keys using the **Object.keys()**
prototype method.

---
```js
const car = {
make: 'Toyota',
model: 'Camry',
year: 2020
};
const keys = Object.keys(car);

console.log(keys);
```

The above code will print an array of strings, where each string is a key in the car object. `['make', 'model', 'year']`

## The challenge:

Create a file named `object-keys.js`.

In that file, define a variable named `car` like this:

```js
const car = {
make: 'Honda',
model: 'Accord',
year: 2020
};
```

Then define another variable named `keys` like this:
```js
const keys = Object.keys(car);
```

Use `console.log()` to print the `keys` variable to the terminal.

Check to see if your program is correct by running this command:

```bash
javascripting verify object-keys.js
```
8 changes: 7 additions & 1 deletion problems/object-keys/solution.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
---

#
# CORRECT.

Good job using the Object.keys() prototype method. Remember to use it when you need to list the keys of an object.

The next challenge is all about **functions**.

Run `javascripting` in the console to choose the next challenge.

---
2 changes: 1 addition & 1 deletion problems/object-properties/solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Good job accessing that property.

The next challenge is all about **functions**.
The next challenge is all about **object keys**.

Run `javascripting` in the console to choose the next challenge.

Expand Down
8 changes: 8 additions & 0 deletions solutions/object-keys/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const car = {
make: 'Toyota',
model: 'Camry',
year: 2020
};
const keys = Object.keys(car);

console.log(keys);

0 comments on commit 62945d2

Please sign in to comment.