Skip to main content

Practice ยท 2 of 2

Accordion State

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.

Difficulty: intermediate

Back to lesson: Practice: Stateful Components โ€” Practice