* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
1.6 KiB
1.6 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
bd7123c9c549eddfaeb5bdef | 使用方括号查找字符串中的第一个字符 | 1 | https://scrimba.com/c/ca8JwhW | 18341 | use-bracket-notation-to-find-the-first-character-in-a-string |
--description--
方括号表示法是一种在字符串中的特定index
(索引)处获取字符的方法。
大多数现代编程语言,如JavaScript,不同于人类从 1 开始计数。它们是从 0 开始计数,这被称为 基于零 的索引。
例如, 在单词 "Charles" 中索引 0 上的字符为 "C",所以在var firstName = "Charles"
中,你可以使用firstName[0]
来获得第一个位置上的字符。
--instructions--
使用方括号获取变量lastName
中的第一个字符,并赋给变量firstLetterOfLastName
。
提示
如果你遇到困难了,不妨看看变量firstLetterOfFirstName
是如何赋值的。
--hints--
firstLetterOfLastName
的值应该是L
。
assert(firstLetterOfLastName === 'L');
你应该使用中括号。
assert(code.match(/firstLetterOfLastName\s*?=\s*?lastName\[.*?\]/));
--seed--
--after-user-code--
(function(v){return v;})(firstLetterOfLastName);
--seed-contents--
// Setup
var firstLetterOfLastName = "";
var lastName = "Lovelace";
// Only change code below this line
firstLetterOfLastName = lastName; // Change this line
--solutions--
var firstLetterOfLastName = "";
var lastName = "Lovelace";
// Only change code below this line
firstLetterOfLastName = lastName[0];