Ask coding questions

← Back to all posts
How do i make a countdown timer?
icelite

I need help with making a countdown timer and notification system when it goes off, could anyone help? comment pls if you can!

Answered by Whacko [earned 5 cycles]
View Answer
Voters
jjrice2233
McJoe21
icelite
Comments
hotnewtop
Whacko

Using the setInterval() JavaScript code, you can make a countdown.

icelite

ok, thnx! then... what HTML do i do? @JavaMaster1

Whacko

@Ravens0606

It's JavaScript, so you need to use <script>.

Whacko

@Ravens0606 easy peasy, lemon squeezy

icelite
Whacko

@Ravens0606 Did it help? I can give you a code that way a <p> element shows the countdown.

icelite

yes! i would like the <p> pls too! @JavaMaster1

icelite

but thnx! @JavaMaster1

Whacko

@Ravens0606 K, here's the code:

Does it work? I used document.getElementById().

icelite

Im sorry, but it didnt work! @JavaMaster1

Whacko

@Ravens0606 Lemme just double-check my code...
JavaScript isn't easy!

icelite

Ok! and... I agree! @JavaMaster1

Whacko

@Ravens0606 Oops... I used value instead of innerHTML.
Here's the working code:

Now it should work.

Whacko

@Ravens0606 Also, you should practice your JavaScript. This website is really good. It might even help you with html!

icelite

Thanks! Can i alter that in any way and have it like the person using it can choose the set time? @JavaMaster1

icelite
Whacko

@Ravens0606 K, here's the code with the user input:

Yeesh, that's a lot of code! Sorry I took so long. Does it work?

icelite

it works PERFECTLY! Thank you!! @JavaMaster1

Whacko

@Ravens0606 Do I get the cycles?

icelite

yep! you get 5 cycles! @JavaMaster1

Whacko

@Ravens0606 Thanks!

NISHoriginal

In Python, you can also use the time library:

I hope it helped.

icelite
RavenDad

Not at school

Bookie0

Hi what language?

icelite
Bookie0
icelite

Thanks! @Bookie0

icelite

@Bookie0 Also, do you know how to make the person set the timer?

Bookie0
icelite

do you know how to make the person set the timer? @Bookie0

Coder100

you can use new Date() for that @Ravens0606

Coder100
Bookie0

i guess you can input the user to choose the timer...?

maybe this can help:

https://stackoverflow.com/questions/54658075/javascript-set-a-timer-based-on-user-input

@Ravens0606

icelite

ok... i am a pretty new coder.. have you ever made a timer that i can refrence? @Bookie0

Coder100
icelite

ok thnx @Coder100

icelite

ok... where is the countdown code? @Coder100

Coder100

script.js @Ravens0606

Coder100

line 44 is approx it @Ravens0606

icelite

thnx @Coder100

Coder100

np did it work @Ravens0606

Bookie0

duh you gave it to him lmao @Coder100

Coder100
Coder100

well just making sure lol @Bookie0

Bookie0

yea ofc ;) @Coder100

icelite

nope, but thnx! @Coder100

Coder100

@Ravens0606 send repl

icelite
Coder100
icelite