Question 11
Back to Exercise
The code below runs without an error, but its result is wrong. Which statement correctly identifies the bug?
const prices = { pen: 10, book: 50, bag: 899 };
function priceOf(item) {
return prices.item;
}
console.log(priceOf("book"), priceOf("bag"));
- A prices.item reads a property literally named "item" – use prices[item] Correct
- B The keys must be quoted
- C item must be converted to a number
- D Functions cannot read outer objects
Correct Answer: Option A
Dot notation never evaluates the name. prices[item] uses the parameter's value and prints 50 899.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!