2.7 KiB
2.7 KiB
id, title, localeTitle, challengeType
id | title | localeTitle | challengeType |
---|---|---|---|
56533eb9ac21ba0edf2244c7 | Accessing Object Properties with Dot Notation | Acceso a las propiedades del objeto con notación de puntos | 1 |
Description
.
) Y notación de corchetes ( []
), similar a una matriz.
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 de cómo usar la notación de puntos ( .
) Para leer la propiedad de un objeto:
var myObj = {
prop1: "val1",
prop2: "val2"
};
var prop1val = myObj.prop1; // val1
var prop2val = myObj.prop2; // val2
Instructions
testObj
usando la notación de puntos. Establezca la variable hatValue
igual al hat
propiedad del objeto y establezca la variable shirtValue
igual a la shirt
propiedad del objeto.
Tests
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>"ballcap"</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>"jersey"</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");'
Challenge Seed
// 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 Test
console.info('after the test');
Solution
var testObj = {
"hat": "ballcap",
"shirt": "jersey",
"shoes": "cleats"
};
var hatValue = testObj.hat;
var shirtValue = testObj.shirt;