Basic Data Structures - Access Property Names with Bracket Notation

How come you cannot use dot notation within this function?

let foods = {
  apples: 25,
  oranges: 32,
  plums: 28,
  bananas: 13,
  grapes: 35,
  strawberries: 27
};

function checkInventory(scannedItem) {
  // Only change code below this line
return foods[scannedItem];
  // Only change code above this line
}

console.log(checkInventory("apples"));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63

Challenge: Basic Data Structures - Access Property Names with Bracket Notation

Link to the challenge:

Dot notation only works with the exact, literal name of the property

Ok, i’ll remember that, thank you

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.