Search the Community
Showing results for tags 'Count Down timer'.
-
Hello every one, today I created the count down timer , but I want to make using OOP style this time. the place where I stuck, is the setTimeout method can't call my class/function every 1000 miliseconds. Please I need your help, where I mess things up? Your help is highy appreciate, Thank you. Bellow is my code. <script type="text/javascript"> window.onload = function(){ function ticTock(ddt){ this.currentDate =new Date(); this.dueDate = new Date(ddt); this.diffDate = this.dueDate.getTime()-this.currentDate.getTime(); if(this.diffDate<=0){ clearTimeout(timer); document.write("closed") } this.seconds = Math.floor(this.diffDate/1000); this.minutes = Math.floor(this.seconds/60); this.hours = Math.floor(this.minutes/60); this.days = Math.floor(this.hours/24); this.hours %=24,this.minutes %=60,this.seconds%=60; this.remainder = this.days+'|'+this.hours+"|"+this.minutes+"|"+this.seconds; var timer = setTimeout(function(){ ticTock(ddt); },1000); } dueDate = "December 25, 2017 00:01:00"; dueDate2 = "December 25, 2019 00:01:00"; var obj = new ticTock(dueDate); var obj2 = new ticTock(dueDate2); document.body.innerHTML = obj.seconds; } </script>