Files
Randell Dawson 1494a50123 fix(guide): restructure curriculum guide articles (#36501)
* fix: restructure certifications guide articles
* fix: added 3 dashes line before prob expl
* fix: added 3 dashes line before hints
* fix: added 3 dashes line before solutions
2019-07-24 13:29:27 +05:30

891 B

title
title
Access Property Names with Bracket Notation

Access Property Names with Bracket Notation


Problem Explanation

  • Using bracket notation simply write the return statement in the checkInventory() function.
  • The following code block demonstrates the required syntax.

Example:

let juice = {
  apple: 1.15,
  orange: 1.45
};
function checkInventory(scannedItem) {
  return juice[scannedItem];
}

Solutions

Solution 1 (Click to Show/Hide)
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"));