Programming Exercises

Create a component that renders a paragraph with a random color every time a button is clicked.

Easy

Problem Statement

Create a component that renders a paragraph with a random color every time a button is clicked.

Sample Output

The paragraph text color changes to a random color when the button is clicked.

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
import React, { useState } from "react"; const RandomColor = () => { const [color, setColor] = useState("black"); const changeColor = () => { // Generate and set a random color }; return ( <div> <p style={{ color }}>This is random color text.</p> <button onClick={changeColor}>Change Color</button> </div> ); }; export default RandomColor;
Log in or sign up to run or submit your code.Log inSign up
Expected Output
The paragraph text color changes to a random color when the button is clicked.