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
2022-10-20 09:13:17 -07: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];