(() => {
const intervalId = setInterval(() => {
// update countdown timer
if (distance < -(ELAPSED_GAMETIME_IN_MS)) {
// set EXPIRED
clearInterval(intervalId);
}
else if (distance < 0) {
// set LIVE
}
}, 1000);
})();
EDIT
Working example
This example utilizes moment because it’s a great utility that provides all necessary math and formatting for dates and is perfect for this scenario.
Because my event does not expire at the end of the countdown, it ends approximately one hour after starting.
So can someone help me add another condition so that in the interval of that time instead of showing me Expired, it shows Live or something similar?
Thank you so much!
Comments
Comment posted by dillon
Could you please provide more context of your code? It appears that you’ve only copied a portion of the code in reference.
Comment posted by codepen.io/iraffleslowd/pen/povGNdo
Hello, I hosted the code in codepen since it was impossible for me to upload it to the site using the integrated editor. Here it is:
Comment posted by dillon
I’m not sure I understand the anticipated outcome at this point. A useful exercise might be using the
Comment posted by slowdmelendez360
Thanks for solving the problem. Can you please give me an example with the code working, how about the NFL game? I owe you my life, hahaha.
Comment posted by dillon
Yeah, no worries. I can update it with a working example.
Comment posted by slowdmelendez360
It will not work, because the condition is that when it is less than zero it shows: “Expired.” Although in else you say: “else do this” will not, because it has already met the first condition. Anyway, I thank you infinitely for trying to help me.
Comment posted by dillon
I would have figured this would be the answer given the phrasing of your question. Since you say this doesn’t solve your problem, I must ask what is your intended result? I can’t say that it is clear at this point. @slowdmelendez360
Comment posted by slowdmelendez360
@CrankyCoder For example, an NFL game that starts on January 22 at 20:00. I must establish that time, right? Then: ** var countDownDate = new Date (“Jan 22, 2020 20:00:00”). getTime (); ** It works perfect, but at the moment my counter arrives at that time specifically (by the if condition) * if (distance <0) { clearInterval (x); document.getElementById ("demo"). innerHTML = "EXPIRED"; } }, 1000); *
Comment posted by slowdmelendez360
“Expired” will appear on my website, but we know that the game has just begun. Then I want to know how I can tell my js that when it arrives at 20:00 the event has just begun and I want it to show on my website: “LIVE” and that after an hour it shows: “Expired” I hope I have explained myself better. Thank you.
Comment posted by dillon
Thanks for the detailing further. I understand and have provided a solution. Please update your original question for future readers.