Menu
Coddy logo textTech

Greetings with Arrow Function

Lesson 13 of 14 in Coddy's Function Declarations in JavaScript course.

challenge icon

Challenge

Easy

You 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