2018-09-30 23:01:58 +01:00
|
|
|
---
|
|
|
|
id: 587d7dac367417b2b2512b74
|
|
|
|
title: Use Dot Notation to Access the Properties of an Object
|
|
|
|
challengeType: 1
|
2019-08-05 09:17:33 -07:00
|
|
|
forumTopicId: 301333
|
2018-09-30 23:01:58 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
## Description
|
|
|
|
<section id='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 06:20:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
let duck = {
|
|
|
|
name: "Aflac",
|
|
|
|
numLegs: 2
|
|
|
|
};
|
|
|
|
console.log(duck.name);
|
|
|
|
// This prints "Aflac" to the console
|
|
|
|
```
|
|
|
|
|
2019-10-27 15:45:37 -01:00
|
|
|
Dot notation is used on the object name, <code>duck</code>, followed by the name of the property, <code>name</code>, to access the value of "Aflac".
|
2018-09-30 23:01:58 +01:00
|
|
|
</section>
|
|
|
|
|
|
|
|
## Instructions
|
|
|
|
<section id='instructions'>
|
2019-10-27 15:45:37 -01:00
|
|
|
Print both properties of the <code>dog</code> object to your console.
|
2018-09-30 23:01:58 +01:00
|
|
|
</section>
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
```yml
|
2018-10-04 14:37:37 +01:00
|
|
|
tests:
|
2019-02-26 08:54:06 +05:30
|
|
|
- text: Your code should use <code>console.log</code> to print the value for the <code>name</code> property of the <code>dog</code> object.
|
|
|
|
testString: assert(/console.log\(.*dog\.name.*\)/g.test(code));
|
|
|
|
- text: Your code should use <code>console.log</code> to print the value for the <code>numLegs</code> property of the <code>dog</code> object.
|
|
|
|
testString: assert(/console.log\(.*dog\.numLegs.*\)/g.test(code));
|
2018-09-30 23:01:58 +01:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
```js
|
|
|
|
let dog = {
|
|
|
|
name: "Spot",
|
|
|
|
numLegs: 4
|
|
|
|
};
|
2020-03-08 07:46:28 -07:00
|
|
|
// Only change code below this line
|
2018-09-30 23:01:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
let dog = {
|
|
|
|
name: "Spot",
|
|
|
|
numLegs: 4
|
|
|
|
};
|
|
|
|
console.log(dog.name);
|
|
|
|
console.log(dog.numLegs);
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|