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

1.6 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
bd7123c9c450eddfaeb5bdef Use Bracket Notation to Find the Nth Character in a String 1 使用括号表示法查找字符串中的第N个字符

Description

您还可以使用括号表示法来获取字符串中其他位置的字符。请记住,计算机从0开始计数因此第一个字符实际上是第0个字符。

Instructions

让我们尝试使用括号表示法将thirdLetterOfLastName设置为等于lastName变量的第三个字母。 暗示
如果卡住,请尝试查看secondLetterOfFirstName变量声明。

Tests

tests:
  - text: <code>thirdLetterOfLastName</code>变量的值应为<code>v</code> 。
    testString: 'assert(thirdLetterOfLastName === "v", "The <code>thirdLetterOfLastName</code> variable should have the value of <code>v</code>.");'
  - text: 您应该使用括号表示法。
    testString: 'assert(code.match(/thirdLetterOfLastName\s*?=\s*?lastName\[.*?\]/), "You should use bracket notation.");'

Challenge Seed

// Example
var firstName = "Ada";
var secondLetterOfFirstName = firstName[1];

// Setup
var lastName = "Lovelace";

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

After Test

console.info('after the test');

Solution

// solution required