Skip to content
Advertisement

Add value from textbox to counter

I’m learning javascript and I want to create a simple clock. I want for user to be able to change minutes by entering a number in textbox and pressing a button, so when that number is displayed and when the seconds are counted to 60, that displayed number increase by 1, my code won’t work, help pls:

JavaScript
JavaScript

Advertisement

Answer

You have a few problems in your code. The main mistake is that your variable minutes is not defined in the function incrementMinutes() where you are trying to use it. You have to calculate it again.

Other improvements that you can make are:

  • Remove the return in your incrementSeconds and incrementMinutes function
  • Have only 1 setInterval, and call incrementMinutes when seconds reach 60.

You can see a snippet here below:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement