Command Palette

Search for a command to run...

Hectal
Phase 0: Start Here: Why React
React · Exercise 4 of 5 PreviousNext
Beginner

A like button

Build a button with id="like". It starts with the text Like. Clicking it switches it to Liked and gives it the class liked. Clicking again switches back to Like with no liked class.

Keep one piece of state (true or false) and work out both the text and the class from it.

What Check tests

  1. It starts as Like without the liked class
  2. One click shows Liked with the liked class
  3. A second click goes back to Like without the class

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.