Need some help with my JavaScript Timer

Hello,

Im new to javascript but I wanted to do a timer and I followed a tutorial.
It works but when I try do add another one only the first one works.

What can I do to make the seconds one works?

Thanks

Here are My Files

First of all, I’m a little confused. You have a variable and a function with the name “startTimer” - in the same scope, no less (as near as I can tell, the function is never used). You also have once called “StartTimer”.

I don’t understand the logic here:

    if(h.value == 0 && m.value == 0 && s.value == 0){
        h.value = 0;
        m.value = 0;
        s.value = 0;
  }

If they are 0, then you’re going to set them to 0. How are they every going to be anything but 0?

Furthermore, this:

start.addEventListener('click', function(){
    function startInterval(){
        startTimer = setInterval(function(){
            timer();
        }, 1000);
    }
    startInterval()
})

Why is it a function wrapped in a function that gets called? Wouldn’t this do the same?

start.addEventListener('click', function(){
    startTimer = setInterval(function(){
        timer();
    }, 1000);
})

You also have some undeclared variables, like Timer, tickaudio, and frameCount.

Ye I edit some of the code.
I started learning javascript today so I have almost no idea about it.
Its just for a friend of mine.
Thanks for the advice.

Can you give me an idea how to make both of them work at the same time.
I tried a lot of ways but none of them worked.
:roll_eyes:

Uhhh, OK…

I might suggest that this is too much to attempt on your first day.

In any case, I can’t see your new code so I have no idea what is going on. If you aren’t going to do this in an online IDE, could you put it in a github repo? That would be an easier way to share what you’ve done.

But as I said, you may want to spend some time learning the basics of JS first. FCC has some free curriculum. If you know HTML and CSS well, you can skip the first certificate and go right into JS.

As to getting two timers working, well, they’re going to need separate timers. Have you gotten one timer working? I’d focus on that.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.