How To Create Greetings Message Using JavaScript
Submitted by alpha_luna on Monday, June 6, 2016 - 16:54.
In this tutorial, we are going to learn how to create Greetings Message using JavaScript. We learn on how to display greetings message according to the time of the day using JavaScript source code. Kindly copy and paste the source code below to the BODY tag of your page.
JavaScript Source Code
This script will display the greetings message using the time of the day. Kindly copy and paste the source code below to the BODY tag of your page.- <center>
- <h2 style="color:blue;">
- How To Create Greetings Message Using JavaScript
- </h2>
- <script>
- var Time_of_The_Day=new Date()
- var hours=Time_of_The_Day.getHours()
- if (hours>=5&&hours<=11)
- //GREETING MESSAGE FOR MORNING
- document.write('<h2>Hello! Good Morning! Have a nice day.</h2>')
- else if (hours==12)
- //GREETING MESSAGE FOR NOON
- document.write('<h2>Good Noon Visitor! </h2>')
- else if (hours>=13&&hours<=17)
- //GREETING MESSAGE FOR AFTERNOON
- document.write('Example:<h2 style="color:#1982d1;">Good Afternoon! </h2>')
- else if (hours>=18&&hours<=20)
- //MESSAGE FOR EVENING (6pm-8pm)
- document.write('<h2>Good Evening! </h2>')
- else if (hours>=21&&hours<=11)
- //GREETING MESSAGE FOR NIGHT (9pm-11pm)
- document.write('<h2>Good Night! </h2>')
- else
- //GREETING MESSAGE FOR LATE NIGHT (12pm-4am)
- document.write('<h2>Wow! You`re still awake. Working Late?</h2>')
- </script>
- </center>
This is the result of the source code above:
So what can you say about this work? Share your thoughts in the comment section below or email me at [email protected]. Practice Coding. Thank you very much.Add new comment
- 1433 views