Clock in web by java script | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Clock in web by java script

hello guys i have a digital clock on my website.i created it with java script. when i insert the script code in my html code,after running the page, after one second everything will lost. I don't know what is the problem, help me. this is the java script code: function printTime(){ var date = new Date(); var h = date.getHours(); var m = date.getMinutes(); var s = date.getSeconds(); document.body.innerHTML = h + ":" + m + ":" + s; } function clock() { setInterval(printTime ,1000); }

12th Apr 2017, 10:39 PM
Beny Saberi
Beny Saberi - avatar
3 Answers
+ 11
I just checked it and works perfectly fine...
12th Apr 2017, 11:50 PM
Gami
Gami - avatar
+ 3
and this is my html code: <div> <script> clock(); </script> </div>
12th Apr 2017, 10:40 PM
Beny Saberi
Beny Saberi - avatar
0
<script>标签放在<body>里
13th Apr 2017, 3:35 AM
sheng chen
sheng chen - avatar