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

1.9 KiB

id title challengeType videoUrl localeTitle
bd7123c9c452eddfaeb5bdef Use Bracket Notation to Find the Nth-to-Last Character in a String 1 Use a notação de suporte para localizar o caractere N-para-último em uma seqüência de caracteres

Description

Você pode usar o mesmo princípio que acabamos de usar para recuperar o último caractere em uma string para recuperar o caractere de enésima a última. Por exemplo, você pode obter o valor da terceira para a última letra da string var firstName = "Charles" usando firstName[firstName.length - 3]

Instructions

Use a notação de colchetes para localizar o penúltimo caractere na string lastName . Sugestão
Tente observar a declaração da variável thirdToLastLetterOfFirstName se você ficar preso.

Tests

tests:
  - text: <code>secondToLastLetterOfLastName</code> deve ser &quot;c&quot;.
    testString: 'assert(secondToLastLetterOfLastName === "c", "<code>secondToLastLetterOfLastName</code> should be "c".");'
  - text: Você tem que usar o <code>.length</code> para obter a segunda última letra.
    testString: 'assert(code.match(/\.length/g).length === 2, "You have to use <code>.length</code> to get the second last letter.");'

Challenge Seed

// Example
var firstName = "Ada";
var thirdToLastLetterOfFirstName = firstName[firstName.length - 3];

// Setup
var lastName = "Lovelace";

// Only change code below this line
var secondToLastLetterOfLastName = lastName;

After Test

console.info('after the test');

Solution

// solution required