0
Digital clock code
I have written this code and it's failing to run what did I do wrong this is the code: <!DOCTYPE html> <html> <head> <title>Digital Clock</title> <script> setInterval(function(){ var currentTime = new Date(); var hours = currentTime.getHours(); var minutes = currentTime.getMinutes(); var seconds = currentTime.getSeconnds(); var period ="AM"; if(hours >= 12){ period ="PM"; } if(hours > 12){ hour = hours - 12; } if(minutes < 10){ minutes = "0"+minutes; } if(seconds < 10){ seconds = "0"+seconds; } var clockTime = hours ":" + munutes ":" + seconds " " + period; var clock = document.getElementById('clock'); clock.innerText ='clockTime'; },1000); </script> </head> <body> <div id="clock"></div> </body> </html>
3 Answers
+ 5
- You missed + operator while concatenating the string.
- clockTime shouldn't be within single quote (' ') in innerText assignment.
- There were some spelling errors
Fixed code :)
https://code.sololearn.com/WvkWZ6F0Hv18/?ref=app
+ 1
thank very much
0
please help