Skip to main content

Practice · 2 of 2

Accordion State

CHALLENGE
Difficulty: intermediate+25 XP

Write createAccordion(count) that RETURNS an object with toggle(i), isOpen(i), and openCount(). Exactly one section may be open at a time (an accordion, not independent collapsibles): toggling the open section closes it; toggling a closed section opens it and closes the previous one. Out-of-range indexes must not crash or change state. Initially all closed.

Back to lesson: Practice: Stateful Components — Practice