M
M
Maxim Benets2022-04-03 01:32:03
HTML
Maxim Benets, 2022-04-03 01:32:03

How to make a user greeting depending on what time it is?

Hello!
It is necessary to implement the possibility that, depending on the time of the user of the site, he would display different text.

For example, at 2 pm: "Good afternoon"
At 9 pm: "Good evening"
At 2 am: "Good night"
At 6 am: "Good morning!"

I think you can implement this using the date class on js, I tried, but I didn’t succeed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lorem Ipsum, 2022-04-03
@teaCode

const hours = new Date().getHours()
const someDiv = document.getElementById('hello')
if hours >= 12 {
    someDiv.innerHTML = "Добрый день"
} else if hours ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question