Programming Exercises

Write a React component that renders a button with a random label every time the page is refreshed.

Easy

Problem Statement

Write a React component that renders a button with a random label every time the page is refreshed.

Sample Input

labels = ['Click me!', 'Press here!', 'Try me!']

Sample Output

The button displays a random label from the array.

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
import React from "react"; const RandomLabelButton = () => { const labels = ["Click me!", "Press here!", "Try me!"]; const randomLabel = "Picked Label"// Pick a random label from the array return <button>{randomLabel}</button>; }; export default RandomLabelButton;
Log in or sign up to run or submit your code.Log inSign up
Input
labels = ['Click me!', 'Press here!', 'Try me!']
Expected Output
The button displays a random label from the array.