One thing to note that he just sorta skips over is the reason for ++ working and +=1 not working. ++ assumes the value is an integer, += does not. Therefore it treats the innerHTML value as it truly is, a string, and just concatenates onto the value ex: 0111111. This becomes important if say you wanted to increment or decrement by a value different than 1. You would need to parseInt the innerHTML to turn the string into an integer before manipulating it and then remember to reinclude the path back to where you want to put it. Be careful though, if you use parseInt you need to make sure there is a starting numeric value, so give your counter a starting value in the HTML such as 0 (makes sense) like he does. Otherwise you will get the result NaN (not a number). ex: let countNum = parseInt(document.querySelector('.countNum').innerHTML) function countUp(){ countNum+=2 document.querySelector('.countNum').innerHTML = countNum }
Hi, thank you for the lesson. I have one problem, when I press the button instead of the numbers going it, NaN just pops up. Could you please help me? Thanks!
see my comment above, it may help you. I explain one reason for getting NaN. Though you posted this 2 months ago so likely you figured out your issue by now