2018-10-10 18:03:03 -04:00
---
id: 56533eb9ac21ba0edf2244c7
title: Accessing Object Properties with Dot Notation
challengeType: 1
2019-08-28 16:26:13 +03:00
videoUrl: https://scrimba.com/c/cGryJs8
forumTopicId: 16164
2018-10-10 18:03:03 -04:00
localeTitle: Доступ к объектным свойствам с нотами Dot
---
## Description
2019-08-28 16:26:13 +03:00
< section id = 'description' >
There are two ways to access the properties of an object: dot notation (< code > .< / code > ) and bracket notation (< code > []< / code > ), similar to an array.
Dot notation is what you use when you know the name of the property you're trying to access ahead of time.
Here is a sample of using dot notation (< code > .< / code > ) to read an object's property:
```js
var myObj = {
prop1: "val1",
prop2: "val2"
};
var prop1val = myObj.prop1; // val1
var prop2val = myObj.prop2; // val2
```
< / section >
2018-10-10 18:03:03 -04:00
## Instructions
2019-08-28 16:26:13 +03:00
< section id = 'instructions' >
Прочитайте значения свойств < code > testObj< / code > с использованием точечной нотации. Установите переменную < code > hatValue< / code > равное свойству объекта < code > hat< / code > и установить переменную < code > shirtValue< / code > равной свойству объекта < code > shirt< / code > .
< / section >
2018-10-10 18:03:03 -04:00
## Tests
< section id = 'tests' >
```yml
tests:
2019-08-28 16:26:13 +03:00
- text: < code > hatValue</ code > should be a string
testString: assert(typeof hatValue === 'string' );
- text: The value of < code > hatValue</ code > should be < code > "ballcap"</ code >
testString: assert(hatValue === 'ballcap' );
- text: < code > shirtValue</ code > should be a string
testString: assert(typeof shirtValue === 'string' );
- text: The value of < code > shirtValue</ code > should be < code > "jersey"</ code >
testString: assert(shirtValue === 'jersey' );
- text: You should use dot notation twice
testString: assert(code.match(/testObj\.\w+/g).length > 1);
2018-10-10 18:03:03 -04:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
// Setup
var testObj = {
"hat": "ballcap",
"shirt": "jersey",
"shoes": "cleats"
};
// Only change code below this line
var hatValue = testObj; // Change this line
var shirtValue = testObj; // Change this line
```
< / div >
2019-08-28 16:26:13 +03:00
### After Tests
2018-10-10 18:03:03 -04:00
< div id = 'js-teardown' >
```js
2019-08-28 16:26:13 +03:00
(function(a,b) { return "hatValue = '" + a + "', shirtValue = '" + b + "'"; })(hatValue,shirtValue);
2018-10-10 18:03:03 -04:00
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
2019-08-28 16:26:13 +03:00
var testObj = {
"hat": "ballcap",
"shirt": "jersey",
"shoes": "cleats"
};
var hatValue = testObj.hat;
var shirtValue = testObj.shirt;
2018-10-10 18:03:03 -04:00
```
2019-08-28 16:26:13 +03:00
2018-10-10 18:03:03 -04:00
< / section >