1.7 KiB
1.7 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
bd7123c9c452eddfaeb5bdef | ブラケット記法を使用して文字列の最後から N 番目の文字を取得する | 1 | https://scrimba.com/c/cw4vkh9 | 18344 | use-bracket-notation-to-find-the-nth-to-last-character-in-a-string |
--description--
文字列の最後の文字を取得する場合に使用したものと同じ手法で、最後から N 番目の文字を取得することができます。
たとえば、const firstName = "Augusta"
という文字列の最後から 3 番目の文字の値を取得するには、firstName[firstName.length - 3]
と記述します。
例:
const firstName = "Augusta";
const thirdToLastLetter = firstName[firstName.length - 3];
thirdToLastLetter
の値は文字列 s
となります。
--instructions--
ブラケット記法を使用して、lastName
文字列の最後から 2 番目の文字を取得してください。
ヒント: 解答できない場合は上記の例を参考にしてください。
--hints--
secondToLastLetterOfLastName
は文字 c
となる必要があります。
assert(secondToLastLetterOfLastName === 'c');
.length
を使用して、最後から 2 番目の文字を取得する必要があります。
assert(code.match(/\.length/g).length > 0);
--seed--
--after-user-code--
(function(v){return v;})(secondToLastLetterOfLastName);
--seed-contents--
// Setup
const lastName = "Lovelace";
// Only change code below this line
const secondToLastLetterOfLastName = lastName; // Change this line
--solutions--
const lastName = "Lovelace";
const secondToLastLetterOfLastName = lastName[lastName.length - 2];