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

2.5 KiB

id title challengeType videoUrl localeTitle
56533eb9ac21ba0edf2244c7 Accessing Object Properties with Dot Notation 1 Acessando propriedades de objeto com notação de ponto

Description

Há duas maneiras de acessar as propriedades de um objeto: notação de ponto ( . ) E notação de colchetes ( [] ), semelhante a uma matriz. A notação de pontos é o que você usa quando sabe o nome da propriedade que está tentando acessar antecipadamente. Aqui está uma amostra de uso de notação de ponto ( . ) Para ler a propriedade de um objeto:
var myObj = {
prop1: "val1",
prop2: "val2"
};
var prop1val = myObj.prop1; // val1
var prop2val = myObj.prop2; // val2

Instructions

Leia os valores de propriedade de testObj usando a notação de ponto. Defina a variável hatValue igual ao hat propriedade do objeto e defina a variável shirtValue igual à shirt propriedade do objeto.

Tests

tests:
  - text: <code>hatValue</code> deve ser uma string
    testString: 'assert(typeof hatValue === "string" , "<code>hatValue</code> should be a string");'
  - text: O valor de <code>hatValue</code> deve 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> deve ser uma string
    testString: 'assert(typeof shirtValue === "string" , "<code>shirtValue</code> should be a string");'
  - text: O valor de <code>shirtValue</code> deve ser <code>&quot;jersey&quot;</code>
    testString: 'assert(shirtValue === "jersey" , "The value of <code>shirtValue</code> should be <code>"jersey"</code>");'
  - text: Você deve usar a notação de ponto duas vezes
    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