14var days = 0;
15
16// Update the count down every 1 second
17var x = setInterval(function() {1819 // Get today's date and time20 now = new Date().getTime();2122 // Find the distance between now and the count down date23 distance = countDownDate - now;2425 // Time calculations for days,26 days = Math.floor(distance / (1000 * 60 * 60 * 24));272829 // Display the result in the element with id="demo"3031 document.getElementById("christmasDayCountdown").innerHTML = days + " days left until Christmas " ;3233 // If the count down is finished, write some text34 if (distance < 0) {35 clearInterval(x);36 document.getElementById("christmasDayCountdown").innerHTML = "";37 }38}, 1000);39
40// // days since christmas was OVER
41
10/*Christmas day countdown */
11var countDownDate = new Date("Dec 25, 2023 23:59:59").getTime();
12var now = 0;
13var distance =0;14var days = 0;
15
16// Update the count down every 1 second
8}
9
10/*Christmas day countdown */
11var countDownDate = new Date("Dec 25, 2023 23:59:59").getTime();12var now = 0;
13var distance =0;
14var days = 0;
9
10/*Christmas day countdown */
11var countDownDate = new Date("Dec 25, 2023 23:59:59").getTime();
12var now = 0;13var distance =0;
14var days = 0;
15
11var countDownDate = new Date("Dec 25, 2023 23:59:59").getTime();
12var now = 0;
13var distance =0;
14var days = 0;15
16// Update the count down every 1 second
17var x = setInterval(function() {
Declare variables at the top of their scope as it improves code readability, performance and also helps in code navigation.
The vars-on-top
rule generates warnings when variable declarations are not used serially at the top of a function scope or the top of a program. By default variable declarations are always moved (“hoisted”) invisibly to the top of their containing scope by the JavaScript interpreter. This rule forces the programmer to represent that behavior by manually moving the variable declaration to the top of its containing scope.
// Variable declarations in a block:
function doSomething() {
var first;
if (true) {
first = true;
}
var second;
}
// Variable declaration in for initializer:
function doSomething() {
for (var i=0; i<10; i++) {}
}
function doSomething() {
var first;
var second; //multiple declarations are allowed at the top
if (true) {
first = true;
}
}
function doSomething() {
var i;
for (i=0; i<10; i++) {}
}