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

Notice Banner States

easy50%1 of 2 solved

Problem statement

A reusable function that drives a notice banner through four states using Vanilla TypeScript and standard DOM APIs. The page provides an existing banner element — the function updates that element in place, and its appearance is driven by state rather than by styles set on the element.

Demo

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

What to implement

  • Take a banner, a state, and a message, and put the banner into that state.
  • Handle four states — info, success, warning, and error — each one looking different.
  • Show only one state at a time. When the state changes, the old one must go away.
  • Show the message you were given, word for word. If the message looks like code, show it as plain words instead of letting it become part of the page.
  • Let screen readers announce the banner, and match how urgent the state is.
  • Let the banner be hidden. Hiding empties the message and leaves the banner in no state at all.
  • Change how the banner looks by changing its state, never by styling the banner directly.
  • Change the banner you were given, rather than building a new one to take its place.
  • Leave anything else already on the banner alone.
  • Everything the banner shows must come from what you were given. Nothing should be fixed in advance.

More in Dom Selection & Manipulation

See the module
Product Card RendererBuild an entire product card in TypeScript from a product object (name, price, rating, inStock, imageAlt) — create every element, set text content, the image alt, a data-* attribute for the id, and a stock class derived from inStock. Format the price to two decimals. The renderer returns the node without ever touching the document, and two calls with the same product produce two independent nodes.25%2 of 8 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.