StaffCoder
TypeScript
Vanilla TypeScriptTypeScript 7.0
6 modules · 24 challengesSign up
Module 1 · Dom Selection & Manipulation

Product Card Renderer

easy25%2 of 8 solved

Problem statement

A reusable function that builds a complete product card from a product object using Vanilla TypeScript and standard DOM APIs. The page provides only an empty mount element — the entire card is created programmatically and returned as a detached DOM node.

Demo

The page, styles, and mount element are already scaffolded and wired. Only the createProductCard function is missing — implement it in src/productCard.ts so every test passes. Do not edit any other file.

What to implement

  • Take a product and build a card that shows its name, image, price, rating, and stock status.
  • Show each piece of information in its own separate element.
  • Show the price with exactly two decimals.
  • Show whether the product is in stock or out of stock.
  • Tag the card so it can be identified by the product's id.
  • Give the card a single label that reflects whether it is in stock or out of stock.
  • Return the finished card without placing it on the page yourself.
  • Building a card twice should give you two completely separate cards.
  • Everything shown on the card must come from the product you were given — nothing should be hardcoded.

More in Dom Selection & Manipulation

See the module
Notice Banner StatesImplement a banner controller that switches between four states (info, success, warning, error) using classList only, sets the message text via textContent, and updates role and aria-live to match the state. Hiding the banner clears the message and removes every state class so states never overlap.50%1 of 2 solvedeasyTable Row Builder Build table rows from an array of records using createElement and a DocumentFragment, appending to <tbody> in a single operation. Money cells receive a numeric class; each row carries a data-* id; cell text is set via textContent so a value containing angle brackets renders as text, not markup; and an empty array leaves the <tbody> untouched.100%1 of 1 solvedeasyDashboard Tile GridBuild one tile per metric from an array (label, value, unit, delta, target), each field in its own slot, with a data-* attribute for the metric key and a trend class derived from the sign of delta (including zero). Tiles whose value is below target carry a below-target marker; an empty array renders a no-data element and no tiles at all.50%1 of 2 solvedeasy

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.