javascript - JS is refusing to loop a function -


this question has answer here:

i having problem countdown. have made countdown js change html refuses loop. have setinterval , have tried for, while , loops none work. appreciate help.

html:

<body>     <center>     <h1> input date , time want countdown to!</h1>     <form>         second:<input id="seconds" type="number"><br>         minute:<input id="minutes" type="number"><br>         hour:<input id="hours" type="number"><br>         day:<input id="days" type="number"><br>         month:<input id="months" type="text"><br>         year:<input id="years" type="number"><br>     </form>     <button onclick="start()">calculate!</button>     <h1 id="yearsres"></h1>years<br>     <h1 id="monthsres"></h1>months<br>     <h1 id="daysres"></h1>days<br>     <h1 id="hoursres"></h1>hours<br>     <h1 id="minutesres"></h1>minutes<br>     <h1 id="secondsres"></h1>seconds<br>     </center> </body> 

js:

function start() {     var myvar = setinterval(test(), 1000) }  function test() {     console.log("hi"); }  function calculateseconds(sec) {     var year = document.getelementbyid("years").value;     var month = document.getelementbyid("months").value;     var day = document.getelementbyid("days").value;     var hour = document.getelementbyid("hours").value;     var minute = document.getelementbyid("minutes").value;     var second = document.getelementbyid("seconds").value;     var countdownto = new date(month + " " + day + "," + " " + year + " " + hour + ":" + minute + ":" + second);     var epochto = countdownto.gettime()/1000.0;     var current = new date();     var epochcurrent = current.gettime()/1000.0;     var epochcountdown = epochto - epochcurrent;     var t = parseint(epochcountdown);     var years = 0;     var months = 0;     var days = 0;     var = 1;      if(t>31556926){         years = parseint(t/31556926); t = t-(years*31556926);            }     if(t>2629743){         months = parseint(t/2629743); t = t-(months*2629743);        }     if(t>86400){         days = parseint(t/86400); t = t-(days*86400);     }     var hours = parseint(t/3600);     t = t-(hours*3600);     var minutes = parseint(t/60);     t = t-(minutes*60);       document.getelementbyid("yearsres").innerhtml = years;     document.getelementbyid("monthsres").innerhtml = months;     document.getelementbyid("daysres").innerhtml = days;     document.getelementbyid("hoursres").innerhtml = hours;     document.getelementbyid("minutesres").innerhtml = minutes;     document.getelementbyid("secondsres").innerhtml = t;  } 

by adding () test function call it. setinterval method takes reference function (name of function) , interval in milliseconds. can used this:

function start() {     var myvar = setinterval(test, 1000); } 

or this:

function start() {     var myvar = setinterval(function() {         test();     }, 1000); } 

also if need pass parameters function can this:

function start() {     var myvar = setinterval(test, 1000, "first param", "second param"); } 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -