0

How to create an endless countdown timer loop, made of days hours minutes and seconds?

https://code.sololearn.com/WNghJv3Imcq5/#html

28th Feb 2017, 11:29 AM
Sam Sung
Sam Sung - avatar
15 Antworten
+ 5
@Sam Sung wrote: << i shall try them and get back to yu with the results. Later i can post the script that i have done since its different from the one you have made. >> It sounds like if you're lying, and just wait for someone write it for you ^^ You're lucky, your topic has inspired me, and I've done my version, even if you don't deserve it :P https://code.sololearn.com/Wt7K7MGvgG1I/#js ( some animations, and basic responsive design inside )
1st Mar 2017, 2:56 PM
visph
visph - avatar
+ 4
First you need to know which year it is. For example, your code should result 2017 for now. Then find the date of 31 December of this year in milliseconds. It is the end of this year. Consider the time 23:59:59:999. Calculate the difference between now and the end of this year. Finally show the result. Be aware that the result is in milliseconds. You need to do some calculations to find number of days, hours, minutes and seconds. As solo learn is a learning app, I don't share code here. But if you stuck, there is one in my profile.
28th Feb 2017, 2:38 PM
Mohammad Mehrabi
Mohammad Mehrabi - avatar
+ 3
What do you mean by "endless"?
28th Feb 2017, 12:23 PM
Mohammad Mehrabi
Mohammad Mehrabi - avatar
+ 3
@Sam Sung wrote: "i tried different if and for combination and couldn't get it right because i couldn't get where it should be placed in the function." In this case, post your code attempt, and you'll get help to get it right ;) Anyway, it's no fair to delete the initial rules from your question, and post a code that give the impress you've asked for Christmass countdown instead of new year one ;P
2nd Mar 2017, 5:34 AM
visph
visph - avatar
+ 3
Your condition is wrong, at least: 'remTime %=0' is equivalent to doing a division by zero. So, JS don't raise an error, but the returned value is NaN, what's equivalent to false ^^
2nd Mar 2017, 5:55 AM
visph
visph - avatar
+ 3
Probably... but I don't know: you're giving only extract of code without context, and modifying your asking each time you get an answer, saying that you already have found yourself ^^
2nd Mar 2017, 6:10 AM
visph
visph - avatar
+ 1
Make an if state ments if blah blah blah then it starts the count down if 364:24:60:60 ten subtract one every second and so on if 364:24:60:0 then sub one from the second 60 and make an if statement if 0:0:0:0 then restart the program or use if else statements
28th Feb 2017, 2:12 PM
Jack
+ 1
Thank you jack and Mohammad for the answers, i shall try them and get back to you with the results. Later i can post the script that i have done since its different from the one you have made.
28th Feb 2017, 7:24 PM
Sam Sung
Sam Sung - avatar
+ 1
Can you check another question i have posted about geolocation the code is there too in my codes.. On that question i have no clue how to do it.. So i wish you could help. And thank you all friends you rock
2nd Mar 2017, 5:32 AM
Sam Sung
Sam Sung - avatar
0
For example a new year countdown. when it hitd the new year the timer becomes 0-0-0-0. I want it to start a new countdown immediately for the next new year
28th Feb 2017, 12:29 PM
Sam Sung
Sam Sung - avatar
0
Visph, first of all thanks for the answer, i haven't checked your code yet and I'll public mine in the next hour, the problem is that i have it on my computer and i use solo learn on my phone Second of all, i came here to learn and my goal is to understand because i tried different if and for combination and couldn't get it right because i couldn't get where it should be placed in the function. Now if you look at my code and change the date to a one that has passed for example 27 of February, my countdown starts counting in negative numbers
2nd Mar 2017, 5:19 AM
Sam Sung
Sam Sung - avatar
0
Fellas the code link is in the description
2nd Mar 2017, 5:28 AM
Sam Sung
Sam Sung - avatar
0
Visph well coming from Russia Christmas here is on the 7th of January not on the 25th plus many people don't celebrate Christmas so i thought it will be legit to ask about the new year instead hehe But what is important here is that I'm not trying to steal ideas so back to your first point hehe.. But what can you comment on my code.. How to get it working??
2nd Mar 2017, 5:39 AM
Sam Sung
Sam Sung - avatar
0
Visph the code if (remTime %= 0) {var eventDate = eventDate.getTime(now.getfullYear(),11,25);} else {var eventDate = eventDate.getTime(now.getfullYear()+1,11,25);} As you can see i posted the working code, but in my attempts i used now. Getfullyear instead of writing 2017... I thought this might work. It for some reason it's not...
2nd Mar 2017, 5:50 AM
Sam Sung
Sam Sung - avatar
0
Visph i figured this out the moment i posted it lmao... That's abit embarrassing.. But does the condition look right if i change the remtime is not equal to zero?
2nd Mar 2017, 6:04 AM
Sam Sung
Sam Sung - avatar