What will this Liquid code output? ```liquid {% assign total = 0 -%} {%- for item in cart.items -%} {%- if item.product.type == "Shirt" -%} {%- assign total = total | plus: item.quantity -%} {%- endif -%} {%- endfor -%} {{- total -}} ``` Given the following cart contents: ```json { "items": [ {"product": {"type": "Shirt"}, "quantity": 2}, {"product": {"type": "Pants"}, "quantity": 1}, {"product": {"type": "Shirt"}, "quantity": 3} ] } ```

### Explanation This question tests understanding of Shopify's cart object and Liquid iteration: 1. We initialize `total = 0` 2. We iterate through `cart.items` 3. For each item: - Check if product type is "Shirt" - If true, add item's quantity to total 4. Final calculation: - First Shirt: quantity 2 - Second Shirt: quantity 3 - Pants are ignored - Total: 2 + 3 = 5 5. Whitespace control (-) ensures clean output

Answer Options:

  • 5
  • 6
  • 3
  • 2
Shopify Free Test
← PreviousQuestion 1 of 1Finish →
00
← PreviousFinish →
Copyright ©Michael Bollin. Found some mistake?[email protected]