This code is simple it is used to get the scanned Items and return their value if the scannedItems aren't there then it will return undefined, but for some reason the dot notation doesn't work for my function but only the bracket notation! i want to know out of curiosity why isn't it working for dot notation with detailed explanation
The code with dot notation
let foods = {
apples: 25,
oranges: 32,
plums: 28,
bananas: 13,
grapes: 35,
strawberries: 27
};
function checkInventory(scannedItem) {
var inventory = foods.scannedItem;
return inventory;
}
console.log(checkInventory("apples"));
let foods = {
apples: 25,
oranges: 32,
plums: 28,
bananas: 13,
grapes: 35,
strawberries: 27
};
function checkInventory(scannedItem) {
var inventory = foods[scannedItem];
return inventory;
}
console.log(checkInventory("apples"));