Files
freeCodeCamp/curriculum/challenges/ukrainian/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-first-character-in-a-string.md
2023-01-13 09:48:11 -08:00

2.2 KiB
Raw Blame History

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. Це називається індексацією на основі нуля.

Наприклад, символом з індексом 0 у слові Charles буде C. Тому, якщо const firstName = "Charles", ви можете отримати значення першої літери рядка, використовуючи firstName[0].

Приклад:

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

firstLetter матиме значення рядка C.

--instructions--

Використайте дужкову нотацію, щоб знайти перший символ у змінній lastName та призначте його до 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];