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

1.8 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
bd7123c9c452eddfaeb5bdef استخدم علامات الأقواس للعثور على رمز معين قبل الأخير في المقطع النصي 1 https://scrimba.com/c/cw4vkh9 18344 use-bracket-notation-to-find-the-nth-to-last-character-in-a-string

--description--

يمكنك استخدام نفس المبدأ الذي استخدمناه لاسترداد آخر حرف في مقطع نصي لتسترد أي حرف ما قبل الحرف الأخير.

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

مثال:

const firstName = "Augusta";
const thirdToLastLetter = firstName[firstName.length - 3];

سيحتوي thirdToLastLetter قيمة s من المقطع النصي.

--instructions--

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

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

--hints--

يجب أن ينتج secondToLastLetterOfLastName حرف c.

assert(secondToLastLetterOfLastName === 'c');

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

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];