I want to alert, good morning based upon time | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

I want to alert, good morning based upon time

https://code.sololearn.com/WYhyIL8Wigjp/?ref=app

10th Jun 2020, 1:18 PM
Mustafha Ahmad
Mustafha Ahmad - avatar
17 Answers
+ 3
use if else on hours
10th Jun 2020, 1:19 PM
Gordon
Gordon - avatar
+ 2
No worries, it's javascript :)
10th Jun 2020, 3:18 PM
Calviղ
Calviղ - avatar
11th Jun 2020, 7:55 AM
Emmanuel
Emmanuel - avatar
+ 1
If(hours<12) printGoodMorning();
10th Jun 2020, 1:46 PM
Calviղ
Calviղ - avatar
+ 1
var time = new Date(); if (time.getHours() < 12) { alert("Good morning"); } else { alert("Good afternoon"); } //just copy this into js and boom done
10th Jun 2020, 6:46 PM
sithlord77 jr
sithlord77 jr - avatar
0
That's not working.. Send me some code..
10th Jun 2020, 1:27 PM
Mustafha Ahmad
Mustafha Ahmad - avatar
0
You are not using alert () function
10th Jun 2020, 1:45 PM
Kashyap Kumar
Kashyap Kumar - avatar
0
It's javascript .....
10th Jun 2020, 2:34 PM
Mustafha Ahmad
Mustafha Ahmad - avatar
0
It's not worked out
10th Jun 2020, 4:17 PM
Mustafha Ahmad
Mustafha Ahmad - avatar
0
Try make a function called printGoodMorning to print "Good morning".
10th Jun 2020, 4:25 PM
Calviղ
Calviղ - avatar
0
I want alert just once,but using if else,it creates alerts for continuously...
11th Jun 2020, 3:16 AM
Mustafha Ahmad
Mustafha Ahmad - avatar
0
// this only alert once at 9:00am If(hours===9 && mins===0) alert('Good morning');
11th Jun 2020, 4:06 AM
Calviղ
Calviղ - avatar
0
It shouldn't do that just leave it out of the main function to only run when the page is loaded
11th Jun 2020, 4:16 AM
sithlord77 jr
sithlord77 jr - avatar
0
Although I'll add if you want to do that simple add some sort of var time = new Date(); var first = true; if (first) { if (time.getHours() < 12) { alert("Good morning"); } else { alert("Good afternoon"); } first = false; } //just copy this into js and boom done
11th Jun 2020, 4:19 AM
sithlord77 jr
sithlord77 jr - avatar
0
Use that
11th Jun 2020, 7:55 AM
Emmanuel
Emmanuel - avatar
0
If (hours<12) PrintGoodMorning() If else (hours<18) PrintGoodAfternoon() Else PrintGoodNight()
11th Jun 2020, 9:37 PM
Diego Diaz Garcia
Diego Diaz Garcia - avatar
0
You can also use time module
12th Jun 2020, 2:29 AM
《A$# ☆ $ING#》
《A$# ☆ $ING#》 - avatar