Files
freeCodeCamp/curriculum/challenges/japanese/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-first-character-in-a-string.md
2022-03-23 15:22:04 +01:00

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

ブラケット記法を使用すると、文字列内の特定のインデックスにある文字を取得できます。

JavaScript をはじめとする現代のほとんどのプログラミング言語では、人間のように 1 から数え始めることをせず、 0 から数え始めます。 これをゼロベースのインデックスといいます。

たとえば、Charles という単語のインデックス 0 の文字は C です。 したがって、const firstName = "Charles" とした場合は、firstName[0] とすることでこの文字列の 1 文字目の値を取得できます。

例:

const firstName = "Charles";
const firstLetter = firstName[0];

firstLetter の値は文字列 C となります。

--instructions--

ブラケット記法を使用して、lastName 変数の 1 文字目を取得し、それを firstLetterOfLastName に代入してください。

ヒント: 解答できない場合は上記の例を参考にしてください。

--hints--

firstLetterOfLastName 変数の値は L となる必要があります。

assert(firstLetterOfLastName === 'L');

ブラケット記法を使用してください。

assert(code.match(/firstLetterOfLastName\s*=\s*lastName\s*\[\s*\d\s*\]/));

--seed--

--after-user-code--

(function(v){return v;})(firstLetterOfLastName);

--seed-contents--

// Setup
let firstLetterOfLastName = "";
const lastName = "Lovelace";

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

--solutions--

let firstLetterOfLastName = "";
const lastName = "Lovelace";

// Only change code below this line
firstLetterOfLastName = lastName[0];