What's wrong with this counter implementation? 🔢 ```liquid {% assign counter %} {% for product in collection.products %} {% assign counter = counter | plus: 1 %} <div class="grid-item grid-item--{{ counter }}"> {{ product.title }} </div> {% endfor %} ```

### Explanation The code has an issue with counter initialization. The line `{% assign counter %}` is incorrect syntax and will cause an error. In Liquid, the `assign` tag requires both a variable name and a value. Without a value assignment, the counter variable remains undefined and cannot be incremented. The correct implementation would be to initialize the counter with a value: ```liquid {% assign counter = 0 %} {% for product in collection.products %} {% assign counter = counter | plus: 1 %}
{{ product.title }}
{% endfor %} ``` Reference: [Liquid Iteration](https://shopify.dev/api/liquid/tags/iteration)

Answer Options:

  • Wrong increment syntax
  • Counter not initialized properly
  • Missing type casting
  • Nothing, code is correct
Shopify Free Test
← PreviousQuestion 1 of 1Finish →
00
← PreviousFinish →
Copyright ©Michael Bollin. Found some mistake?[email protected]