0
JavaScript Date() function
Hello, SoloLearners. I've been playing with js a little bit and tried to make a simple clock function that would display time in html document. It's pretty easy to do it, and I had no problems at all, but one thing that's bugging me is seconds. For example, variable s represents seconds. If s is less than 9, let's say it's 5 seconds in the current minute, seconds are displayed as "5". Is there a way to make it display as "05"? I'm pretty sure that the answer is easy, but I couldn't figure it out. Thanks.
2 Respostas
+ 2
I don't know what your code is but maybe this will help you figure it out:
if(s <= 9)
second_string = "0" + s;
else
second_string = "" + s;
It will put a zero at the beginning of second_string if s has only one digit
0
use do-while loops to add one by one units to your counters using setInterval function to call it every 1000 ms. Thats a way to see it...