Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

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

Try your code in this preview. Submit marks it done.

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;