javascript - Tried to do a chronometer, but failed -


i trying simple chronometer, 1 number keeps counting infinite. please keep in mind trying correct own code, refrain answering "this post duplicate of ...", because won't understand other examples. reason code doesn't work, please help.

<!doctype html> <html>     <head>     <style>     #screen {     position: relative;     border: 2px solid black;     width: 800px;     height: 600px;     top: 50px;     left: 500px;     }      #chronometer {     position: absolute;     top: 150px;     left: 300px;     font-size: 100px;     width: 300px;     height: 300px;     }     </style>     </head>     <body>     <div id="screen">         <div id="chronometer"></div>     </div>     <script>     var chronometer = setinterval(increasechronometer, 1000);     function increasechronometer () {         var chronometernumber = 1;         document.getelementbyid("chronometer").innerhtml = chronometernumber;         chronometernumber++;     }     </script>     </body> </html> 

you defining "chronometernumber" variable inside function, gets created , initialized "1" every time invoke function.

just move line "var chronometernumber=1" outside function , should work fine.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -