freeCodeCamp/curriculum/challenges/portuguese/02-javascript-algorithms-an.../basic-javascript/use-bracket-notation-to-fin...

1.5 KiB

id title challengeType videoUrl forumTopicId dashedName
bd7123c9c450eddfaeb5bdef Usar notação de colchetes para encontrar o enésimo caractere em uma string 1 https://scrimba.com/c/cWPVJua 18343 use-bracket-notation-to-find-the-nth-character-in-a-string

--description--

Você também pode usar notação de colchetes para pegar caracteres em outras posições em uma string.

Lembre-se de que computadores começam contando do 0. Então, o primeiro caractere é na verdade o caractere na posição 0.

Exemplo:

const firstName = "Ada";
const secondLetterOfFirstName = firstName[1];

secondLetterOfFirstName teria o valor da string d.

--instructions--

Vamos tentar definir thirdLetterOfLastName para ser igual a terceira letra da variável lastName usando notação de colchetes.

Dica: tente olhar o exemplo acima se você ficar travado.

--hints--

A variável thirdLetterOfLastName deve ter o valor de v.

assert(thirdLetterOfLastName === 'v');

Você deve usar notação de colchetes.

assert(code.match(/thirdLetterOfLastName\s*=\s*lastName\s*\[\s*\d\s*\]/));

--seed--

--after-user-code--

(function(v){return v;})(thirdLetterOfLastName);

--seed-contents--

// Setup
const lastName = "Lovelace";

// Only change code below this line
const thirdLetterOfLastName = lastName; // Change this line

--solutions--

const lastName = "Lovelace";
const thirdLetterOfLastName = lastName[2];