function startTimer() { userInput = 120; if(userInput.length == 0){ alert("Please enter a value"); } else { var numericExpression = /^[0-9]+$/; function display( notifier, str ) { document.getElementById(notifier).innerHTML = str; } function toMinuteAndSecond( x ) { return Math.floor(x/60) + ":" + x%60; } function setTimer( remain, actions ) { (function countdown() { display("countdown", toMinuteAndSecond(remain)); actions[remain] && actions[remain](); (remain -= 1) >= 0 && setTimeout(countdown, 1000); })(); } setTimer(userInput, { 0: function () { alert( "Time Is Up. Please Sumbit Vote."); } }); } }