- 2
I want to alert, good morning based upon time
17 odpowiedzi
+ 3
use if else on hours
+ 2
No worries, it's javascript :)
+ 1
If(hours<12) printGoodMorning();
+ 1
var time = new Date();
if (time.getHours() < 12) {
alert("Good morning");
} else {
alert("Good afternoon");
}
//just copy this into js and boom done
0
That's not working..
Send me some code..
0
You are not using alert () function
0
It's javascript .....
0
It's not worked out
0
Try make a function called printGoodMorning to print "Good morning".
0
I want alert just once,but using if else,it creates alerts for continuously...
0
// this only alert once at 9:00am
If(hours===9 && mins===0) alert('Good morning');
0
It shouldn't do that just leave it out of the main function to only run when the page is loaded
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
0
Use that
0
If (hours<12)
PrintGoodMorning()
If else (hours<18)
PrintGoodAfternoon()
Else
PrintGoodNight()
0
You can also use time module