title: Can someone explain this for/in loop to me?
body: <pre><code>/*
    Write each function according to the instructions.
    
  
    When a function's parameters reference `cart`, it references an object that looks like the one that follows.
    {
      &quot;Gold Round Sunglasses&quot;: { quantity: 1, priceInCents: 1000 },
      &quot;Pink Bucket Hat&quot;: { 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 = &quot;&quot;;
    for (const item in cart){
      inventory += `${Object.values(cart[item])[0]}x${item}\n`;
    }
    return inventory;
    
  }
  
  module.exports = {
    calculateCartTotal,
    printCartInventory,
  };
  
  </code></pre>
  <p>The part that confuses me is the function calculateCartTotal. What I am confused about is how does this loop know to grab priceInCents? for example, if I was to add another value into the object called &quot;weight: 24&quot; assuming that it is 24 grams, how does the object value skip over quantity and weight and just grab priceInCents? Hopefully I am making sense on how I am confused and that someone has an explanation for me!</p>