Files
freeCodeCamp/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-last-character-in-a-string.md

1.4 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
bd7123c9c451eddfaeb5bdef Usar notação de colchetes para encontrar o último caractere em uma string 1 https://scrimba.com/c/cBZQGcv 18342 use-bracket-notation-to-find-the-last-character-in-a-string

--description--

Para pegar a última letra de uma string, você pode subtrair um do tamanho da string.

Por exemplo, se var firstName = "Ada", você pode pegar o valor da última letra da string ao usar firstName[firstName.length - 1].

Exemplo:

var firstName = "Ada";
var lastLetter = firstName[firstName.length - 1];

lastLetter teria o valor da string a.

--instructions--

Use notação de colchetes para descobrir o último caractere na variável lastName.

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

--hints--

lastLetterOfLastName deve ser a letra e.

assert(lastLetterOfLastName === 'e');

Você deve usar .length para pegar a última letra.

assert(code.match(/\.length/g).length > 0);

--seed--

--after-user-code--

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

--seed-contents--

// Setup
var lastName = "Lovelace";

// Only change code below this line
var lastLetterOfLastName = lastName; // Change this line

--solutions--

var lastName = "Lovelace";
var lastLetterOfLastName = lastName[lastName.length - 1];