+ 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
5 ответов
+ 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
}
+ 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;
+ 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
+ 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?
0
Use battery