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

2.6 KiB

id title challengeType videoUrl localeTitle
56533eb9ac21ba0edf2244c7 Accessing Object Properties with Dot Notation 1 Acceso a las propiedades del objeto con notación de puntos

Description

Hay dos formas de acceder a las propiedades de un objeto: notación de puntos ( . ) Y notación de corchetes ( [] ), 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 ( . ) Para leer la propiedad de un objeto:
var myObj = {
prop1: "val1",
prop2: "val2"
};
var prop1val = myObj.prop1; // val1
var prop2val = myObj.prop2; // val2

Instructions

Lea los valores de propiedad de 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>&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");'

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

// solution required