JS_ Why does this code increment by 5 when I told it to do by 1

It's supposed to add a table cell when you click on the "+". Every time you click on it it should add a table cell. But it adds about 5 table cells at once. What's the problem? Sorry, I forgot to put the code https://code.sololearn.com/WaFZt9uKxWO1/#js

9/11/2019 12:49:12 AM


6 Answers

New Answer




Maybe it's in a loop.


Jay Matthews it is in a loop, but I can't figure out why it's not working.


Disect the code. Break it down into smaller pieces.


Jay Matthews I meant to put the code up with the question: https://code.sololearn.com/WaFZt9uKxWO1/#js


Your for loop states that every time your loop is executed and th_names_count is less than 10 to increment it. And your next call is to increment again. So with that said you are incrementing it 2 times per loop. 10 ÷ 2 = 5