Building counter

Hi there,
Im buiding a counter app.
I got an issue with my algorithm scripting.
My intention is every time I click Reset button. It will reset the count back to 0, so when I click Decrease or Increase button it will decrease or increase 1 number at a time from 0.

However, with my code, when I reset, and then increase or decrease it will continue the number from the last count.

Can you help me out please?
See the link below :slight_smile:https://codepen.io/christiesunnie/pen/XWjXRRO

Looking at your reset button callback:

const reset = resetBtn.addEventListener('click', () => {
    valueNum.textContent = count - count; // you could just write 0 :-)
    valueNum.style.color = 'black';
});

There should be a third line where you reset your count variable to 0.

1 Like

Thank you! It works when I reinitialize count variable with 0. Thank you so much!

I have tried, the problem isn’t because I set :
valueNum.textContent = count - count or valueNum.textContent = 0 // they both work.
I don’t know if it might create bug later? with the first solution;

But what I need is the third line of reinitialization of count variable!

1 Like

Lol well that escalated quickly…

.bind(...) is a very powerful tool, allowing you to attach the same function to different contexts, to pass in different parameters, or to use a function (as in this context) as an event listener with custom parameters, other then the Event object.

Not being critical, honest question, does bind(...) enter into the core js track?

Thanks you for your help! That is useful :slight_smile: