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

2.1 KiB

id title challengeType videoUrl forumTopicId dashedName
56533eb9ac21ba0edf2244c7 Acessar propriedades de objetos com notação de pontos 1 https://scrimba.com/c/cGryJs8 16164 accessing-object-properties-with-dot-notation

--description--

Existem duas formas para acessar as propriedades de um objeto: notação de ponto (.) e notação de colchetes ([]), de forma similar a um array.

Notação de ponto é o que você utiliza quando você sabe o nome da propriedade que você está tentando acessar antecipadamente.

Aqui está um exemplo usando notação de ponto (.) para ler uma propriedade do objeto:

const myObj = {
  prop1: "val1",
  prop2: "val2"
};

const prop1val = myObj.prop1;
const prop2val = myObj.prop2;

prop1val teria o valor val1 e prop2val teria o valor val2.

--instructions--

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

--hints--

hatValue deve ser uma string

assert(typeof hatValue === 'string');

O valor de hatValue deve ser a string ballcap

assert(hatValue === 'ballcap');

shirtValue deve ser a string

assert(typeof shirtValue === 'string');

O valor de shirtValue deve ser a string jersey

assert(shirtValue === 'jersey');

Você deve usar notação de ponto duas vezes

assert(code.match(/testObj\.\w+/g).length > 1);

--seed--

--after-user-code--

(function(a,b) { return "hatValue = '" + a + "', shirtValue = '" + b + "'"; })(hatValue,shirtValue);

--seed-contents--

// Setup
const testObj = {
  "hat": "ballcap",
  "shirt": "jersey",
  "shoes": "cleats"
};

// Only change code below this line
const hatValue = testObj;      // Change this line
const shirtValue = testObj;    // Change this line

--solutions--

const testObj = {
  "hat": "ballcap",
  "shirt": "jersey",
  "shoes": "cleats"
};

const hatValue = testObj.hat;
const shirtValue = testObj.shirt;