HTML Academy
Summary of “JavaScript in the browser”. Part 1
Introduction to JavaScript in the browser9/23
Back to the list of tasks
  • 1. Script to start!
  • 2. Ready or not, here I come
  • 3. First class
  • 4. Find every single one
  • 5. Under cover
  • 6. Temporarily unavailable
  • 7. Special offer
  • 8. Summary of “JavaScript in the browser”. Part 1
  • 9. Twelfth program: “Ice cream test”
  • 10. Be careful, children!
  • 11. Creating a card
  • 12. Describe yourself
  • 13. Don’t repeat yourself
  • 14. Refactor and conquer
  • 15. Adding a picture
  • 16. One more function
  • 17. Check yourself
  • 18. Live data
  • 19. Got it in stock? What if I find one?
  • 20. Special offer
  • 21. Start the conveyor
  • 22. Summary of “JavaScript in the browser”. Part 2
  • 23. Thirteenth program: “Ice cream returns”
Be careful, children!
  • Sign up
  • Log in

Register to take up challenges

Registration will only take a minute and let you save your study progress. You can register with your email and password or login via social networks.

or
Log in and continue
  • index.html
  • style.css
  • script.js
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Catalog | Glacie</title> <link rel="stylesheet" href="gllacy/setting.css"> <link rel="stylesheet" href="style.css"> </head> <body> <ul class="goods"> <li class="good"> <h2 class="good__description">Creamy coffee with chunks of chocolate</h2> <img src="gllacy/choco.jpg" width="220" height="220" alt="Creamy coffee with chunks of chocolate"> <p class="good__price">110 ₽/kg</p> </li> <li class="good"> <h2 class="good__description">Creamy lemon with caramel powder</h2> <img src="gllacy/lemon.jpg" width="220" height="220" alt="Creamy lemon with caramel powder"> <p class="good__price">220 ₽/kg</p> </li> <li class="good"> <h2 class="good__description">Creamy with cranberry jam</h2> <img src="gllacy/cowberry.jpg" width="220" height="220" alt="Creamy with cranberry jam"> <p class="good__price">310 ₽/kg</p> </li> <li class="good"> <h2 class="good__description">Creamy with cookie dough</h2> <img src="gllacy/cookie.jpg" width="220" height="220" alt="Creamy with cookie dough"> <p class="good__price">400 ₽/kg</p> </li> <li class="good"> <h2 class="good__description">Creamy creme brulee</h2> <img src="gllacy/creme-brulee.jpg" width="220" height="220" alt="Creamy creme brulee"> <p class="good__price">500 ₽/kg</p> </li> </ul> <script src="script.js"></script> </body> </html>
CSS
.good { position: relative; display: flex; width: 220px; flex-direction: column; align-items: center; min-width: 267px; margin-bottom: 35px; padding: 15px 10px; color: #ffffff; } .good--available::before, .good--unavailable::before { position: absolute; top: 10px; right: 10px; z-index: 1; display: inline-block; padding: 5px 8px; font-weight: bold; font-size: 16px; vertical-align: top; text-align: center; color: #ffffff; background-image: linear-gradient(#e74a35 0%, #f26843 100%); border: none; border-radius: 5px; } .good--hit { width: 100%; order: -1; background-color: rgba(255, 255, 255, 0.2); border-radius: 5px; box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.4); } .good--hit::after { content: ""; position: absolute; top: 5px; left: 5px; z-index: 1; width: 61px; height: 61px; margin: auto; background-image: url("gllacy/hit.svg"); background-repeat: no-repeat; } .good--unavailable { filter: grayscale(1) opacity(0.8); } .good--unavailable::before { content: "Out of stock"; } .good--available::before { content: "In stock"; }
JavaScript
var assortmentData = [ { inStock: true, isHit: false }, { inStock: false, isHit: false }, { inStock: true, isHit: true }, { inStock: true, isHit: false }, { inStock: false, isHit: false } ]; /* Technical assignment Meow! We must display the current state of the products on the store website: “in stock”, “not available”, “bestseller”. Product data is stored in an array with assortmentData objects, each object corresponds to one product and contains the following properties: - inStock: if the value is true, ice cream is available, if it is false, the products is out of stock. - isHit: if the value is true, the ice cream is the most popular among customers. Each product state corresponds to a special class: - Product in stock: good--available. - Unavailable product: good--unavailable. - Bestseller: good--hit. Design the code as the updateCards function, which accepts data arrays. Call it by transferring assortmentData. */

What didn’t you like in this task?

Thanks! We’ll fix everything at once!

Click inside the mini browser to put the focus in this window.

100%
Console
// Input data var assortmentData = [ { inStock: true, isHit: false }, { inStock: false, isHit: false }, { inStock: true, isHit: true }, { inStock: true, isHit: false }, { inStock: false, isHit: false } ]; // Code written during the assignment var updateCards = function (cards) { var elements = document.querySelectorAll('.good'); for (var i = 0; i < elements.length; i++) { var element = elements[i]; var card = cards[i]; var availabilityClass = 'good--unavailable'; if (card.inStock) { availabilityClass = 'good--available'; } element.classList.add(availabilityClass); if (card.isHit) { element.classList.add('good--hit'); } } }; updateCards(assortmentData);

Cookies ∙ Privacy ∙ License Agreement ∙ About ∙ Contacts ∙ © HTML Academy OÜ, 2019−2025

VISAMastercard

Log in

or

Forgot your password?

Sign up

Sign up

or
Log in

Restore access

Have you forgotten your password or lost access to your profile? Enter your email connected to your profile and we will send you a link to restore access.

Forgot to connect your email to the profile? Email us and we’ll help.