javascript - How do I use setInterval with my form to create an alarm clock? -


i'm trying learn javascript , i've decided make things more interesting creating instead of endless reading & no practice. i'm trying build alarm clock.

here's code:

http://codepen.io/anon/pen/dcsax

function wakeup() {     window.location = "https://www.youtube.com/watch?v=dqw4w9wgxcq" } 

i need create function uses setinterval check every few seconds if time set in form equal current time, , if is, execute wakeup function plays rick astley - never gonna give up.

i don't know how write piece of code. please me out can see how it's done?

thanks in advance.

i added id button, , on click set timer function below:

 <input id="scheduletimer" type="button" value="schedule alarm"></input>   function gettimeoutsec() {   var dt = new date();   var currsecs = dt.getseconds() + (60 * dt.getminutes()) + (60 * 60 * dt.gethours());    var am_pm = document.getelementbyid('t').value;   var formhour = parseint(document.getelementbyid('h').value);   if(am_pm == 'pm') {     formhour += 12;   }   var formmin = parseint(document.getelementbyid('m').value);   var formseconds = (formhour * 3600) + (formmin * 60);   return formseconds - currsecs; }  window.onload = function() {    var scheduletimerbutton = document.getelementbyid('scheduletimer');    scheduletimerbutton.addeventlistener('click', function() {        var secremaining = gettimeoutsec();        settimeout(wakeup, secremaining * 1000);    }, false); }; 

link codepen


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -