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

Programming Exercises

Build a component that changes the background color of a <div> when hovered over.

Easy

Problem Statement

Build a component that changes the background color of a

when hovered over.

Sample Output

The <div> changes its background color to blue when hovered over.

Limits

Time: 2s · Memory: 256 MB

Code Editor

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

import React, { useState } from "react";
 
 const HoverColor = () => {
  const [bgColor, setBgColor] = useState("white");
 
  return (
  <div
  style={{ backgroundColor: bgColor, width: "200px", height: "100px" }}
  onMouseEnter={() => {
  // Change the background color to blue
  }}
  onMouseLeave={() => {
  // Reset the background color to white
  }}
  >
  Hover over me!
  </div>
  );
 };
 
 export default HoverColor;