Home > Software design >  Unusual behavior when value of variable change (easy)
Unusual behavior when value of variable change (easy)

Time:01-04

Happy 2k22! I am building a countdown timer. I have two files. The first file takes the countDown time from input and the second from select dropdown .

I have implemented an increment button in the first file. It increases the countDown time by inc seconds i.e. time = time inc.

So what's peculiar?

Thing is that when inc is replaced with any constant value, it works properly.

<button onClick={() => setSecondsRemaining(secondsRemaining   3)}>
      Increment {inc} sec
</button>

But when I used the input to enter the value and supply it through the variable inc, then it does not work. It increases randomly.

<button onClick={() => setSecondsRemaining(secondsRemaining   inc)}>
      Increment {inc} sec
</button>

You can visit InputCountDown.js Edit unusual-behavior-when-value-of-variable-change-easy

  •  Tags:  
  • Related