Programming Exercises

Write a React component that displays a greeting based on the current hour (e.g., 'Good Morning,' 'Good Afternoon').

Easy

Problem Statement

Write a React component that displays a greeting based on the current hour (e.g., 'Good Morning,' 'Good Afternoon').

Sample Output

Good Morning, Good Afternoon, or Good Evening based on the time of day.

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
import React from "react"; const Greeting = () => { const hour = new Date().getHours(); let greeting; // Determine the greeting based on the hour return ( // Display the appropriate greeting <></> ); }; export default Greeting;
Log in or sign up to run or submit your code.Log inSign up
Expected Output
Good Morning, Good Afternoon, or Good Evening based on the time of day.