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

2.0 KiB
Raw Blame History

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

Description

Bracket notation是一种在字符串中的特定index处获取字符的方法。大多数现代编程语言如JavaScript都不像人类那样开始计算。它们从0开始。这称为基于零的索引。例如单词“Charles”中索引0处的字符是“C”。因此如果var firstName = "Charles" ,则可以使用firstName[0]获取字符串第一个字母的值。

Instructions

使用括号表示法查找lastName变量中的第一个字符并将其分配给firstLetterOfLastName暗示
如果卡住,请尝试查看firstLetterOfFirstName变量声明。

Tests

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

Challenge Seed

// Example
var firstLetterOfFirstName = "";
var firstName = "Ada";

firstLetterOfFirstName = firstName[0];

// Setup
var firstLetterOfLastName = "";
var lastName = "Lovelace";

// Only change code below this line
firstLetterOfLastName = lastName;

After Test

console.info('after the test');

Solution

// solution required