--- id: 587d7b7c367417b2b2512b1a title: Access Property Names with Bracket Notation challengeType: 1 videoUrl: '' localeTitle: الوصول إلى خاصية الأسماء مع تدرج قوس --- ## Description
في التحدي الكائن الأول ذكرنا استخدام تدوين قوس كطريقة للوصول إلى قيم الممتلكات باستخدام تقييم متغير. على سبيل المثال ، تخيل أن foods يتم استخدامها في برنامج لسجل النقدية في السوبر ماركت. لدينا بعض الوظائف التي تحدد foods selectedFood ونريد أن نتحقق من أن foods كائن لوجود ذلك الطعام. قد يبدو هذا كالتالي:
السماح selectFood = getCurrentFood (scannedItem)؛
السماح للمخزون = الأطعمة [selectFood] ؛
سيقوم هذا الكود بتقييم القيمة المخزنة في المتغير selectedFood والصادر وإعادة قيمة هذا المفتاح في كائن foods ، أو يتم undefined إذا لم تكن موجودة. يعتبر تدرج قوس مفيد جدًا لأن أحيانًا لا تكون خصائص الكائن معروفة قبل وقت التشغيل أو نحتاج إلى الوصول إليها بطريقة أكثر ديناميكية.
## Instructions
لقد قمنا بتعريف وظيفة ، checkInventory ، الذي يتلقى عنصرًا تم مسحه ضوئيًا كوسيطة. قم scannedItem القيمة الحالية لمفتاح scannedItem في كائن foods . يمكنك افتراض أنه سيتم توفير المفاتيح الصالحة فقط كوسيطة checkInventory .
## Tests
```yml tests: - text: checkInventory هي وظيفة testString: 'assert.strictEqual(typeof checkInventory, "function", "checkInventory is a function");' - text: 'يجب أن يحتوي جسم foods على أزواج القيمة الرئيسية التالية: apples: 25 ، oranges: 32 ، plums: 28 ، bananas: 13 ، grapes: 35 ، strawberries: 27' testString: 'assert.deepEqual(foods, {apples: 25, oranges: 32, plums: 28, bananas: 13, grapes: 35, strawberries: 27}, "The foods object should have only the following key-value pairs: apples: 25, oranges: 32, plums: 28, bananas: 13, grapes: 35, strawberries: 27");' - text: checkInventory("apples") 25 testString: 'assert.strictEqual(checkInventory("apples"), 25, "checkInventory("apples") should return 25");' - text: checkInventory("bananas") 13 testString: 'assert.strictEqual(checkInventory("bananas"), 13, "checkInventory("bananas") should return 13");' - text: checkInventory("strawberries") 27 testString: 'assert.strictEqual(checkInventory("strawberries"), 27, "checkInventory("strawberries") should return 27");' ```
## Challenge Seed
```js let foods = { apples: 25, oranges: 32, plums: 28, bananas: 13, grapes: 35, strawberries: 27 }; // do not change code above this line function checkInventory(scannedItem) { // change code below this line } // change code below this line to test different cases: console.log(checkInventory("apples")); ```
## Solution
```js // solution required ```