2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Access Property Names with Bracket Notation
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Access Property Names with Bracket Notation
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Problem Explanation
|
2018-10-12 15:37:13 -04:00
|
|
|
- Using bracket notation simply write the return statement in the `checkInventory()` function.
|
|
|
|
- The following code block demonstrates the required syntax.
|
|
|
|
|
|
|
|
## Example:
|
|
|
|
```javascript
|
|
|
|
let juice = {
|
|
|
|
apple: 1.15,
|
|
|
|
orange: 1.45
|
|
|
|
};
|
|
|
|
function checkInventory(scannedItem) {
|
|
|
|
return juice[scannedItem];
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Solutions
|
|
|
|
|
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
|
|
|
|
|
|
|
```javascript
|
2018-10-12 15:37:13 -04:00
|
|
|
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
|
|
|
|
return foods[scannedItem];
|
|
|
|
}
|
|
|
|
|
|
|
|
// change code below this line to test different cases:
|
|
|
|
console.log(checkInventory("apples"));
|
|
|
|
```
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
</details>
|