+2

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

Ginfio

6 Answers

New Answer

+1

https://code.sololearn.com/WM5WmrdsR8WJ/?ref=app

+4

Maybe it's in a loop.

+2

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

+2

Disect the code. Break it down into smaller pieces.

+1

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

0

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