Files
freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-first-character-in-a-string.md
2023-02-16 12:04:56 +01:00

2.1 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 كما يفعل البشر. إنهم يبدؤون عند الصفر. يشار إلى هذا بالترتيب من الصفر zero-based indexing.

على سبيل المثال، الرمز في ترتيب 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];