2018-09-30 22:01:58 +00:00
|
|
|
---
|
|
|
|
id: 587d7dac367417b2b2512b74
|
|
|
|
title: Use Dot Notation to Access the Properties of an Object
|
|
|
|
challengeType: 1
|
2019-08-05 16:17:33 +00:00
|
|
|
forumTopicId: 301333
|
2021-01-13 02:31:00 +00:00
|
|
|
dashedName: use-dot-notation-to-access-the-properties-of-an-object
|
2018-09-30 22:01:58 +00:00
|
|
|
---
|
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --description--
|
|
|
|
|
2019-11-22 14:35:10 +00:00
|
|
|
The last challenge created an object with various properties. Now you'll see how to access the values of those properties. Here's an example:
|
2019-05-17 13:20:30 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
let duck = {
|
|
|
|
name: "Aflac",
|
|
|
|
numLegs: 2
|
|
|
|
};
|
|
|
|
console.log(duck.name);
|
|
|
|
```
|
|
|
|
|
2021-03-03 00:12:12 +00:00
|
|
|
Dot notation is used on the object name, `duck`, followed by the name of the property, `name`, to access the value of `Aflac`.
|
2020-11-27 18:02:05 +00:00
|
|
|
|
|
|
|
# --instructions--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
Print both properties of the `dog` object to your console.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --hints--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
Your code should use `console.log` to print the value for the `name` property of the `dog` object.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
```js
|
|
|
|
assert(/console.log\(.*dog\.name.*\)/g.test(code));
|
2018-09-30 22:01:58 +00:00
|
|
|
```
|
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
Your code should use `console.log` to print the value for the `numLegs` property of the `dog` object.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
```js
|
|
|
|
assert(/console.log\(.*dog\.numLegs.*\)/g.test(code));
|
|
|
|
```
|
|
|
|
|
|
|
|
# --seed--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
## --seed-contents--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
let dog = {
|
|
|
|
name: "Spot",
|
|
|
|
numLegs: 4
|
|
|
|
};
|
2020-03-08 14:46:28 +00:00
|
|
|
// Only change code below this line
|
2018-09-30 22:01:58 +00:00
|
|
|
```
|
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --solutions--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
let dog = {
|
|
|
|
name: "Spot",
|
|
|
|
numLegs: 4
|
|
|
|
};
|
|
|
|
console.log(dog.name);
|
|
|
|
console.log(dog.numLegs);
|
|
|
|
```
|