/*
Follow the instructions provided to implement each function.
The parameters of a function that reference `cart` pertain to an object structured like this:
{
"Gold Round Sunglasses": { quantity: 1, priceInCents: 1000 },
"Pink Bucket Hat": { quantity: 2, priceInCents: 1260 }
}
*/
function calculateCartTotal(cart) {
let total = 0;
for (const item in cart){
let quantity = Object.values(cart[item])[0];
let price = Object.values(cart[item])[1];
total += price * quantity;
}
return total;
}
function printCartInventory(cart) {
let inventory = "";
for (const item in cart){
inventory += `${Object.values(cart[item])[0]}x${item}\n`;
}
return inventory;
}
module.exports = {
calculateCartTotal,
printCartInventory,
};
I find the calculateCartTotal function particularly perplexing. My confusion lies in how exactly the loop identifies and retrieves priceInCents from the object. For instance, if I were to introduce another property like "weight: 24," assuming it represents 24 grams, how does the loop specifically target priceInCents without getting tangled up with other properties like quantity or weight? I hope my confusion is articulated clearly, and I'm eager to learn more about this specific behavior!