2.0 KiB
2.0 KiB
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