1.4 KiB
1.4 KiB
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 const firstName = "Ada"
, você pode pegar o valor da última letra da string ao usar firstName[firstName.length - 1]
.
Exemplo:
const firstName = "Ada";
const 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
const lastName = "Lovelace";
// Only change code below this line
const lastLetterOfLastName = lastName; // Change this line
--solutions--
const lastName = "Lovelace";
const lastLetterOfLastName = lastName[lastName.length - 1];