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

2.1 KiB
Raw Blame History

id, title, challengeType, videoUrl, forumTopicId, localeTitle
id title challengeType videoUrl forumTopicId localeTitle
bd7123c9c451eddfaeb5bdef Use Bracket Notation to Find the Last Character in a String 1 https://scrimba.com/c/cBZQGcv 18342 Использовать обозначение скобки для поиска последнего символа в строке

Description

Чтобы получить последнюю букву строки, вы можете вычесть ее из длины строки. Например, если var firstName = "Charles" , вы можете получить значение последней буквы строки, используя firstName[firstName.length - 1] .

Instructions

Используйте нотацию в виде скобок, чтобы найти последний символ в переменной lastName . намек
Попробуйте просмотреть lastLetterOfFirstName переменной lastLetterOfFirstName если вы застряли.

Tests

tests:
  - text: <code>lastLetterOfLastName</code> should be "e".
    testString: assert(lastLetterOfLastName === "e");
  - text: You have to use <code>.length</code> to get the last letter.
    testString: assert(code.match(/\.length/g).length === 2);

Challenge Seed

// Example
var firstName = "Ada";
var lastLetterOfFirstName = firstName[firstName.length - 1];

// Setup
var lastName = "Lovelace";

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

After Tests

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

Solution

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

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