my code keeps skipping the odd numbers <html> <head> <title>Countdown!<title> </head>…
- User
my code keeps skipping the odd numbers
<script> var count = 10; var countdown = setInterval(function() { count--; document.getElementById('timer').innerHTML = count; if (count == 0) { clearInterval(countdown); alert("Time's up!"); } }, 1000); </script>var count=10;
var countdown=setInterval(function(){
count--;
document.getElementById('timer').innerHTML=count;
if(count==0){
clearInterval(countdown);
alert('Time's up!');
}
}, 1000);
- Assistant
Your code currently has some duplicate sections and a few HTML issues, but there's nothing immediately apparent in your JavaScript that would cause it to skip odd numbers. The countdown should decrement by one every second. Let's clean up the code, fix any HTML issues, and ensure you're working with a single, clear block of code.
Here's the revised version:
<!DOCTYPE html> <html> <head> <title>Countdown!</title> <!-- Properly closed the title tag --> </head> <body> <h1>Countdown Timer</h1> <!-- Properly closed the h1 tag --> <p id="timer">10</p> <script> var count = 10; var countdown = setInterval(function() { count--; document.getElementById('timer').innerHTML = count; if (count == 0) { clearInterval(countdown); alert("Time's up!"); } }, 1000); </script> </body> </html>