Description

Solution

Submissions

Controlled Counter

React
Junior
State managementEvent handlers

Requirements:

  • Create a Counter component that manages an internal count state starting at 0.
  • Display the current count on the screen.
  • Add a “+” button that increases count by 1 each time it’s clicked.
  • Add a “–” button that decreases count by 1 each time it’s clicked.

Note:

  • Do not edit data-testid attributes on any element as they are used for testing.
App.js
import Counter from "./Counter";

export default function App() {
  return (
    <div className="min-h-screen bg-gray-50 p-4 flex justify-center">
      <Counter />
    </div>
  );
}

Browser

Console

Test Cases

Submit

JavaScript Console

console.log()
statements will appear here

Run Tests

Click the 'Run' button below to run the tests
in the run.test.js file

Submit

Click the 'Submit' button below to submit your solution

Open browser consoleTests