+ 2

Cant get a StopWatch working

I am new to coding trying to learn Javascript at the moment. I found a YouTube video on how to make a Stop watch I copied it line by line in attempts to try and learn what each line does but I have not been able to get it to work. Any help will be appreciated!! Thank you in advance https://code.sololearn.com/Wu5XVvCiOLTh/?ref=app

12th Apr 2019, 3:04 PM
DiazCode - avatar
5 Antworten
+ 7
Instead of document.getElementById("display").innerHTML = 00:00:00; put document.getElementById("display").innerHTML = "00:00:00"; change status = "started" with status = "started"; You need to close <div class ="container"> with a </div> Need to load the page before your javascript code. So, enclose all your javascript code with window.onload = function() { ... Your js code here }
12th Apr 2019, 4:01 PM
Javier Felipe Toribio
Javier Felipe Toribio - avatar
+ 6
html elements don┬┤t see javascript until all is load. Change buttons in html with <button id ="startStop" >Start</button> <button id ="reset">Reset</button> in javascript, put after reset function the lines document.getElementById("startStop").addEventListener("click",startStop); document.getElementById("reset").addEventListener("click",reset); This variables must be numbers, not strings let seconds =0; let minutes =0; let hours =0;
12th Apr 2019, 7:11 PM
Javier Felipe Toribio
Javier Felipe Toribio - avatar
+ 5
DiazCode From the original code, you provided there two problems that stop the code from running. The first problem was the missing quotation marks as indicated earlier. The second problem was the stopWatch() closing paren was in the wrong spot, meaning it did not encompass all the code it should. https://code.sololearn.com/WGIiERbDBkSt/#js
12th Apr 2019, 11:24 PM
ODLNT - avatar
+ 1
Javier Felipe Toribio thank you so much for the help! I have updated the code with your suggestions but now im getting this error: ÔÇťTypeError: startStop is not a function. (In 'startStop()', 'startStop' is an instance of HTMLButtonElement) at Line: -6ÔÇŁ Any idea why js isnt picking startStop as a function?
12th Apr 2019, 4:54 PM
DiazCode - avatar
Use battery
13th Apr 2019, 3:01 PM
verio elfando