freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-last-character-in-a-string.chinese.md
Kristofer Koishigawa b3213fc892 fix(i18n): chinese test suite (#38220)
* fix: Chinese test suite

Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working.

* fix: ran script, updated testStrings and solutions
2020-03-03 18:49:47 +05:30

1.5 KiB

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
bd7123c9c451eddfaeb5bdef Use Bracket Notation to Find the Last Character in a String 1 使用括号表示法查找字符串中的最后一个字符

Description

为了获得字符串的最后一个字母,您可以从字符串的长度中减去一个字母。例如,如果var firstName = "Charles" ,则可以使用firstName[firstName.length - 1]获取字符串最后一个字母的值。

Instructions

使用括号表示法查找lastName变量中的最后一个字符。 暗示
如果卡住了,请尝试查看lastLetterOfFirstName变量声明。

Tests

tests:
  - text: <code>lastLetterOfLastName</code>应为“e”。
    testString: assert(lastLetterOfLastName === "e");
  - text: 你必须使用<code>.length</code>来获取最后一个字母。
    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 Test

console.info('after the test');

Solution

// solution required