Greetings with Arrow Function
Lesson 13 of 14 in Coddy's Function Declarations in JavaScript course.
Challenge
EasyYou have to write a program that displays a greeting message based on the time of day using an arrow function.
Use the new Date().getHours() method to get the current hour (0-23).
Define an arrow function named getGreeting that takes one argument, hour.
Inside the function, use an if statement to check the hour range:
- If the hour is between 6 and 11 (morning), return "Good morning!".
- If the hour is between 12 and 17 (afternoon), return "Good afternoon!".
- Otherwise, return "Good evening/night!".
Try it yourself
All lessons in Function Declarations in JavaScript
1Course Introduction
What you will learn?3Ways of Function Declaration
Basic FunctionNested FunctionReturning a FunctionFunction ExpressionsArrow FunctionFunction Constructor