1.7 KiB
1.7 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--
方括號表示法(Bracket notation)是一種在字符串中的特定 index(索引)處獲取字符的方法。
大多數現代編程語言,如 JavaScript,不同於人類從 1 開始計數。 它們是從 0 開始計數。 這被稱爲基於零(Zero-based)的索引。
例如,單詞 Charles 的索引 0 的字符是 C。 所以在 var firstName = "Charles" 中,你可以使用 firstName[0] 來獲得第一個位置上的字符。
示例:
var firstName = "Charles";
var firstLetter = firstName[0];
firstLetter 值爲字符串 C 。
--instructions--
使用方括號獲取變量 lastName 中的第一個字符,並賦給變量 firstLetterOfLastName。
提示: 如果卡住了,請嘗試查看上面的示例。
--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];