So I stumbled on some Javascript timer example and there was this function, which gets a number into it and then the function returns the time:
function timer(variable){
return variable > 9 ? variable : "0" + variable;
}
And the whole code would look something like this:
var sec = 0;
function timer(variable){
return variable > 9 ? variable : "0" + variable;
}
setInterval(function(){
$("#time-id").val("Minutes: "+timer(parseInt(sec/60, 10))+" Seconds: "+timer(++sec%60));
}, 1000);
So yes, the setInterval
function is pretty clear to me but about the timer()
.
What is the usage of ?
in it? And how does it understand if I have multiple params given to it. Should it not be marked like this : timer(variable1, variable2){}
?