Pick a Colour Swatch

Write the code, see it run, pass the checks.

The problem

  • easy
  • Code

Offer three colour swatches as buttons named "Coral", "Teal" and "Gold", and a line reading "Chosen: none". Clicking a swatch chooses it: the line reads, for example, "Chosen: Teal", that swatch is pressed (aria-pressed="true") and the others aren't (aria-pressed="false"). Clicking another swatch moves the choice, and clicking the chosen one again keeps it. A "Clear" button goes back to "Chosen: none" with nothing pressed.

Your code must pass

  • Nothing is chosen at first
  • Clicking a swatch chooses only that one
  • Clicking the chosen swatch keeps it
  • Clear removes the choice