foods يتم استخدامها في برنامج لسجل النقدية في السوبر ماركت. لدينا بعض الوظائف التي تحدد foods selectedFood ونريد أن نتحقق من أن foods كائن لوجود ذلك الطعام. قد يبدو هذا كالتالي: السماح selectFood = getCurrentFood (scannedItem)؛سيقوم هذا الكود بتقييم القيمة المخزنة في المتغير
السماح للمخزون = الأطعمة [selectFood] ؛
selectedFood والصادر وإعادة قيمة هذا المفتاح في كائن foods ، أو يتم undefined إذا لم تكن موجودة. يعتبر تدرج قوس مفيد جدًا لأن أحيانًا لا تكون خصائص الكائن معروفة قبل وقت التشغيل أو نحتاج إلى الوصول إليها بطريقة أكثر ديناميكية. checkInventory ، الذي يتلقى عنصرًا تم مسحه ضوئيًا كوسيطة. قم scannedItem القيمة الحالية لمفتاح scannedItem في كائن foods . يمكنك افتراض أنه سيتم توفير المفاتيح الصالحة فقط كوسيطة checkInventory . 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");'
```