freeCodeCamp/curriculum/challenges/spanish/02-javascript-algorithms-an.../basic-javascript/accessing-object-properties...

76 lines
2.6 KiB
Markdown
Raw Normal View History

2018-10-08 17:34:43 +00:00
---
id: 56533eb9ac21ba0edf2244c7
title: Accessing Object Properties with Dot Notation
challengeType: 1
2018-10-10 20:20:40 +00:00
videoUrl: ''
localeTitle: Acceso a las propiedades del objeto con notación de puntos
2018-10-08 17:34:43 +00:00
---
## Description
2018-10-10 20:20:40 +00:00
<section id="description"> Hay dos formas de acceder a las propiedades de un objeto: notación de puntos ( <code>.</code> ) Y notación de corchetes ( <code>[]</code> ), similar a una matriz. La notación de puntos es lo que usa cuando conoce el nombre de la propiedad a la que intenta acceder con anticipación. Aquí hay una muestra del uso de la notación de puntos ( <code>.</code> ) Para leer la propiedad de un objeto: <blockquote> var myObj = { <br> prop1: &quot;val1&quot;, <br> prop2: &quot;val2&quot; <br> }; <br> var prop1val = myObj.prop1; // val1 <br> var prop2val = myObj.prop2; // val2 </blockquote></section>
2018-10-08 17:34:43 +00:00
## Instructions
2018-10-10 20:20:40 +00:00
<section id="instructions"> Lea los valores de propiedad de <code>testObj</code> usando la notación de puntos. Establezca la variable <code>hatValue</code> igual al <code>hat</code> propiedad del objeto y establezca la variable <code>shirtValue</code> igual a la <code>shirt</code> propiedad del objeto. </section>
2018-10-08 17:34:43 +00:00
## Tests
<section id='tests'>
```yml
tests:
- text: <code>hatValue</code> debe ser una cadena
testString: 'assert(typeof hatValue === "string" , "<code>hatValue</code> should be a string");'
- text: El valor de <code>hatValue</code> debe ser <code>&quot;ballcap&quot;</code>
testString: 'assert(hatValue === "ballcap" , "The value of <code>hatValue</code> should be <code>"ballcap"</code>");'
- text: <code>shirtValue</code> debe ser una cadena
testString: 'assert(typeof shirtValue === "string" , "<code>shirtValue</code> should be a string");'
- text: El valor de <code>shirtValue</code> debe ser <code>&quot;jersey&quot;</code>
testString: 'assert(shirtValue === "jersey" , "The value of <code>shirtValue</code> should be <code>"jersey"</code>");'
- text: Deberías usar la notación de puntos dos veces.
testString: 'assert(code.match(/testObj\.\w+/g).length > 1, "You should use dot notation twice");'
```
</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
2018-10-10 20:20:40 +00:00
2018-10-08 17:34:43 +00:00
```
</div>
### After Test
<div id='js-teardown'>
```js
console.info('after the test');
```
</div>
</section>
## Solution
<section id='solution'>
```js
2018-10-10 20:20:40 +00:00
// solution required
2018-10-08 17:34:43 +00:00
```
</section>