qusi Posted April 20, 2020 Share Posted April 20, 2020 Hi JavaScript cracks! I fount that howto and built a countup out of it.https://www.w3schools.com/howto/howto_js_countdown.asp This works well, the only thing I struggle is to include weeks. I can calculate the weeks: var weeks = Math.floor(distance / (1000 * 60 * 60 * 24 * 7)); Bud I can not substract the remaining days, similar to hours, minutes and seconds: var days = Math.floor(distance % (1000 * 60 * 60 * 24 * 7)) / (1000 * 60 * 60 * 24)); Where ist the problem? <strong>countup3:</strong> <p id="countup3"></p> <script> // Set the date we're counting up from var countUpDate3 = new Date("Mar 16, 2020 00:00:00").getTime(); // Update the count down every 1 second var x = setInterval(function() { // Get today's date and time var now = new Date().getTime(); // Find the distance between now and the count up date var distance = now - countUpDate3; // Time calculations for weeks, days, hours, minutes and seconds var weeks = Math.floor(distance / (1000 * 60 * 60 * 24 * 7)); var days = Math.floor(distance % (1000 * 60 * 60 * 24 * 7)) / (1000 * 60 * 60 * 24)); var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((distance % (1000 * 60)) / 1000); // Output the result in an element with id="countup3" document.getElementById("countup3").innerHTML = weeks + " w " + days + " d " + hours + " h " + minutes + " m " + seconds " s "; }, 1000); </script> Link to comment Share on other sites More sharing options...
Ingolme Posted April 20, 2020 Share Posted April 20, 2020 It's just mismatched parentheses on this line: var days = Math.floor(distance % (1000 * 60 * 60 * 24 * 7)) / (1000 * 60 * 60 * 24)); Count the opening brackets and the closing brackets. 1 Link to comment Share on other sites More sharing options...
qusi Posted April 20, 2020 Author Share Posted April 20, 2020 Perfect thaks! I must have been blind in one eye. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now