Friday, May 17, 2024
119
rated 0 times [  121] [ 2]  / answers: 1 / hits: 54418  / 11 Years ago, sat, august 3, 2013, 12:00:00

I want to have a javascript file which checks if current time is between 7pm and 7am. If so it should change the background color on my website to X.
If the current time is not between 7pm and 7am the background color should be Y.
Since I am new to Javascript I do not know everything, and that's why I need your help!


More From » if-statement

 Answers
19
var today = new Date().getHours();
if (today >= 7 && today <= 19) {
document.body.style.background = Red;
} else {
document.body.style.background = Blue;
}


See fiddle.


[#76549] Friday, August 2, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alorac

Total Points: 262
Total Questions: 82
Total Answers: 97

Location: Libya
Member since Mon, Dec 7, 2020
4 Years ago
alorac questions
Sat, Oct 10, 20, 00:00, 4 Years ago
Tue, Sep 22, 20, 00:00, 4 Years ago
Wed, Jul 1, 20, 00:00, 4 Years ago
Wed, Jun 3, 20, 00:00, 4 Years ago
Sun, May 17, 20, 00:00, 4 Years ago
;