javascript - setInterval just won't work -


setinterval won't work, code:

    <script>      var d = new date();     var utc_offset = d.gettimezoneoffset();     d.setminutes(d.getminutes() + utc_offset);     var h = d.gethours();     var m = d.getminutes();     var s = d.getseconds();  function clockupdater() {     if(h >= 0 || h <= 5){         hl = h - 18;     }else if(h >= 6 || h <= 11 ){      hl = h - 12;     }else if(h >= 12 || h <= 17){      hl = h - 6;     }else if(h >= 18){      hl = h - 0;     }      /*     hl = hl - 1;       if(m>1){          ml = 60 - m -1;     }     */      ml = 60 - m;     sl = 60 - s;      document.getelementbyid("timer").innerhtml = hl+":"+ml+":"+sl;  }      setinterval(clockupdater, 1000);  </script>  <body> <div id="timer"></div> </body> 

i'm building timer has count down every 6 hours, setinterval won't work , not working intended, can see went wrong?

the problem here building of h, m , s values done once instead of being done inside clockupdater function.

that's why clock can't updated: you're writing same hour.

move part (including d = new date();) inside function.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -