I am just starting to learn javascript and I'm struggling with removing the expired part of my countdown. When the countdown reaches 0 for days, hours, minutes, etc., I want it to display "Expired" instead.
Below is the JavaScript code:
var items = document.querySelectorAll('#clock');
for (var i = 0, len = items.length; i < len; i++) {
(function () {
var e = new Date("2018-12-31").getTime(),
t = this.querySelector("[data-js=countdown]"),
n = this.querySelector("[data-js=countdown-endtext]"),
day = this.querySelector("[data-js=countdown-day]"),
hour = this.querySelector("[data-js=countdown-hour]"),
min = this.querySelector("[data-js=countdown-minute]"),
sec = this.querySelector("[data-js=countdown-second]"),
s = this.gjs_countdown_interval;
s && s && clearInterval(s);
var l = function (e, t, n, s) {
day.innerHTML = e < 10 ? "0" + e : e,
hour.innerHTML = t < 10 ? "0" + t : t,
min.innerHTML = n < 10 ? "0" + n : n,
sec.innerHTML = s < 10 ? "0" + s : s
},
u = function () {
var day = (new Date).getTime(),
hour = e - day,
min = Math.floor(hour / 864e5),
sec = Math.floor(hour % 864e5 / 36e5),
s = Math.floor(hour % 36e4 / 6e4),
u = Math.floor(hour % 6e4 / 1e3);
l(min, sec, s, u), hour < 0 && (clearInterval(c),
n.innerHTML = "EXPIRED",
t.style.display = "none",
n.style.display = "")
};
if (e) {
var c = setInterval(u, 1e3);
this.gjs_countdown_interval = c,
n.style.display = "none",
t.style.display = "", u()
} else l(0, 0, 0, 0)
}.bind(items[i]))();
}
HTML:
<section class="flex-sect">
<div id="clock" class="countdown">
<span data-js="countdown" class="countdown-cont">
<div class="countdown-block">
<div data-js="countdown-day" class="countdown-digit"></div>
<div class="countdown-label">days</div>
</div>
<div class="countdown-block">
<div data-js="countdown-hour" class="countdown-digit"></div>
<div class="countdown-label">hours</div>
</div>
<div class="countdown-block">
<div data-js="countdown-minute" class="countdown-digit"></div>
<div class="countdown-label">minutes</div>
</div>
<div class="countdown-block">
<div data-js="countdown-second" class="countdown-digit"></div>
<div class="countdown-label">seconds</div>
</div>
</span>
<span data-js="countdown-endtext" class="countdown-endtext"></span>
</div>
</section>
Thank you for your assistance!