• Theory
  • Theory

Thirteenth program: “Ice cream returns”

As soon as you were done with one task, Muffin showed up with another one.

Meow! Do you remember the ice cream shop? You need to create product cards based on the data received from the server.

The cardsData array contains one object for each product. Each object has the following properties:

  • inStock: product availability. If the value is true, the product is available (for such a product, the designer created the good--available class); if it is false, the product is not available (product with the good--unavailable class).
  • imgUrl: link to the product image.
  • text: the product name.
  • price: the product price.
  • isHit: defines if the product is a bestseller. If the value is true, the product is a bestseller. For such a product, class good--hit was created.
  • specialOffer: a special offer, which is only available for bestsellers. Must be in a paragraph with class good__special-offer and must be the last child element in the card.

Here is an example of the markup of one card in the catalog:

<ul class="goods">
  <li class="good">
    <h2 class="good__description">Creamy coffee with chocolate chip</h2>
    <img class="good__image" src="gllacy/choco.jpg" alt="Creamy coffee with chocolate chip">
    <p class="good__price">110 ₽/kg</p>
  </li>
  …
</ul>

Note that the text in the alt attribute of the image must be the same as the name of the product.

Create a renderCards function that takes an array of product data and displays the ice cream cards on the page. Call it with cardsData as the argument.

Note the order in which the elements appear in the product card. Remember that when you insert with appendChild, the elements are added to the end of the parent.

To create a string with a price, use the following concatenation: price + ' ₽/kg'.

When you are done, press Hey boss, here’s your program! to show Muffin the results of your work.

  • index.html
HTML
HTML

You’ve gone to a different page

Click inside the mini-browser to shift the focus onto this window.

100%