Command Palette

Search for a command to run...

Hectal
Phase 8: The DOM
JavaScript · Exercise 4 of 5 PreviousNext
Intermediate

Accent colour and dark mode

Finish two functions. The button wiring is already written (you'll learn events properly in Phase 9).

1. setAccent(color) sets the CSS custom property --accent on the <html> element, so the Buy button changes colour.

2. toggleDark() toggles the class dark on <body>, sets the toggle button's text to Light mode when dark is on and Dark mode when it's off, and returns true if dark mode is now on, false if not.

What Check tests

  1. The Buy button starts teal
  2. setAccent("rgb(255, 0, 0)") turns the Buy button red
  3. toggleDark() turns dark mode on and returns true
  4. Calling it again turns dark mode off and returns false
  5. Clicking the button switches mode and its text

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.