--- id: 56533eb9ac21ba0edf2244c7 title: Accessing Object Properties with Dot Notation challengeType: 1 videoUrl: https://scrimba.com/c/cGryJs8 forumTopicId: 16164 localeTitle: Доступ к объектным свойствам с нотами Dot --- ## Description
There are two ways to access the properties of an object: dot notation (.) and bracket notation ([]), 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 (.) to read an object's property: ```js var myObj = { prop1: "val1", prop2: "val2" }; var prop1val = myObj.prop1; // val1 var prop2val = myObj.prop2; // val2 ```
## Instructions
Прочитайте значения свойств testObj с использованием точечной нотации. Установите переменную hatValue равное свойству объекта hat и установить переменную shirtValue равной свойству объекта shirt .
## Tests
```yml tests: - text: hatValue should be a string testString: assert(typeof hatValue === 'string' ); - text: The value of hatValue should be "ballcap" testString: assert(hatValue === 'ballcap' ); - text: shirtValue should be a string testString: assert(typeof shirtValue === 'string' ); - text: The value of shirtValue should be "jersey" testString: assert(shirtValue === 'jersey' ); - text: You should use dot notation twice testString: assert(code.match(/testObj\.\w+/g).length > 1); ```
## Challenge 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 ```
### After Tests
```js (function(a,b) { return "hatValue = '" + a + "', shirtValue = '" + b + "'"; })(hatValue,shirtValue); ```
## Solution
```js var testObj = { "hat": "ballcap", "shirt": "jersey", "shoes": "cleats" }; var hatValue = testObj.hat; var shirtValue = testObj.shirt; ```