Dynamic Greeting App
React.js
easy
25 mins
A modern React application that displays a real-time greeting message based on the current hour of the day and updates the local time every second.
Problem Description
Create a greeting app that:
- Greets users based on the current hour (morning, afternoon, evening, night).
- Continuously displays and updates the current time in real-time.
- Changes the greeting as the time changes without needing a manual refresh.
Functionality Requirements
- Greeting Message:
"Good Morning! βοΈ"from 5 AM to 12 PM."Good Afternoon! π€οΈ"from 12 PM to 5 PM."Good Evening! π"from 5 PM to 9 PM."Good Night! πβ¨"from 9 PM to 5 AM.
- Live Time Display:
- Displays the user's local time using
toLocaleTimeString(). - Time should update every second using
setInterval.
- Displays the user's local time using
- Visual Layout:
- Styled with a dark background and a bright time card.
- Responsive and centered layout.
- Testability:
- Use
data-testid="greeting"for greeting element. - Use
data-testid="time"for time display.
- Use
Edge Cases & Constraints
- App should automatically transition between greetings at appropriate time thresholds.
- Must work with 24-hour and 12-hour system times.
setIntervalmust be cleared on component unmount.- Ensure emojis and time logic donβt overlap (each hour belongs to one specific greeting).
- Greeting must change seamlessly without user interaction.
Examples
Example 1:
System Time: 2025-05-27T08:30:00
Display Output: Good Morning! βοΈ 08:30:00 AM
Example 2:
System Time: 2025-05-27T21:45:00
Display Output: Good Night! πβ¨ 09:45:00 PM
Preview what you need to build
Companies:
meesho
flipkart
swiggy
Solve Similar questions π₯
Want to upskill? Explore our courses!
Namaste DSA
Master DSA from scratch with numerous problems, and expert guidance.
Namaste React
Wanna dive deep into React and become Frontend Expert? Learn with me now!
Namaste Frontend System Design
The most comprehensive and detailed course for frontend system design.
Namaste Node.js
Wanna dive deep into Node.js? Enroll into `Namaste Node.js` now!
