mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-30 21:03:58 -05:00
2.6 KiB
2.6 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
| id | title | challengeType | videoUrl | forumTopicId | dashedName |
|---|---|---|---|---|---|
| 56533eb9ac21ba0edf2244c9 | الوصول إلى خصائص الكائن باستخدام المتغيرات (Accessing Object Properties with Variables) | 1 | https://scrimba.com/c/cnQyKur | 16165 | accessing-object-properties-with-variables |
--description--
وثمة استخدام آخر لترميز آلأقواس للوصول إلى الخصائص المخزنة كقيمة للمتغير. يمكن أن يكون هذا مفيداً جداً خلال تكرار خصائص الكائن أو عند الوصول إلى جدول البحث.
فيما يلي, مثال على استخدام متغير للوصول إلى خاصية ما:
const dogs = {
Fido: "Mutt",
Hunter: "Doberman",
Snoopie: "Beagle"
};
const myDog = "Hunter";
const myBreed = dogs[myDog];
console.log(myBreed);
سوف يتم عرض Doberman في وحدة التحكم (console).
لاحظ أننا لا نستخدم علامات التنصيص حول اسم المتغير عند استخدامه للوصول إلى الخاصية لأننا نستخدم قيمة المتغير، ليس الاسم.
--instructions--
عيّن متغير playerNumber إلى 16. ثم استخدم المتغير للبحث عن اسم اللاعب وتعيينه إلى player.
--hints--
playerNumber يجب أن يكون رقما
assert(typeof playerNumber === 'number');
المتغير player يجب أن يكون مقطع نصي (string)
assert(typeof player === 'string');
يجب أن تكون قيمة player مقطع نصي Montana
assert(player === 'Montana');
يجب عليك استخدام ترميز ألأقواس للوصول إلى testObj
assert(/testObj\s*?\[.*?\]/.test(code));
لا يجب عليك تعيين قيمة Montana للمتغير player مباشرة.
assert(!code.match(/player\s*=\s*"|\'\s*Montana\s*"|\'\s*;/gi));
يجب أن تستخدم المتغير playerNumber في رمز القوس
assert(/testObj\s*?\[\s*playerNumber\s*\]/.test(code));
--seed--
--after-user-code--
if(typeof player !== "undefined"){(function(v){return v;})(player);}
--seed-contents--
// Setup
const testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};
// Only change code below this line
const playerNumber = 42; // Change this line
const player = testObj; // Change this line
--solutions--
const testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};
const playerNumber = 16;
const player = testObj[playerNumber];