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

1.7 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
bd7123c9c451eddfaeb5bdef استخدم علامات الأقواس (Bracket Notation) للعثور على آخر حرف في مقطع نصي (String) 1 https://scrimba.com/c/cBZQGcv 18342 use-bracket-notation-to-find-the-last-character-in-a-string

--description--

للحصول على آخر حرف من المقطع النصي (String)، يمكنك طرح واحد من طوله.

على سبيل المثال، إذا const firstName = "Ada"، يمكنك الحصول على قيمة الحرف الأخير من المقطع باستخدام firstName[firstName.length - 1].

مثال:

const firstName = "Ada";
const lastLetter = firstName[firstName.length - 1];

سيكون قيمة lastLetter تساوي المقطع النصي a.

--instructions--

استخدم علامات الأقواس للعثور على الحرف الأخير في المتغير lastName.

تلميح: حاول النظر إلى المثال أعلاه إذا كنت عالق.

--hints--

يجب أن يكون lastLetterOfLastName الحرف e.

assert(lastLetterOfLastName === 'e');

يجب عليك استخدام .length للحصول على آخر حرف.

assert(code.match(/\.length/g).length > 0);

--seed--

--after-user-code--

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

--seed-contents--

// Setup
const lastName = "Lovelace";

// Only change code below this line
const lastLetterOfLastName = lastName; // Change this line

--solutions--

const lastName = "Lovelace";
const lastLetterOfLastName = lastName[lastName.length - 1];