+ 2

[SOLVED] Length NULL value error

I am trying to get the length of a str.match in a div section. Works fine👍 Except the NULL value😒. When There isn't a match in the div, the length property throws me an error and can't output a value. (line 30 to 36) How to change the NULL value(default) so it will outputs 0 as default and not an error😉. Any help and/or explanation will be appericiated! https://code.sololearn.com/Wa1fbV4OK7AI/?ref=app

22nd Aug 2018, 6:16 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
4 odpowiedzi
+ 3
if(rollednums[0]==null) { rollednums[0] = 0; } else { rollednums[0] = count.match(/1/g).length; } try it with all affected variables maybe a for loop is a better choice 😉
22nd Aug 2018, 7:11 PM
SouthPoleHillbilly
SouthPoleHillbilly - avatar
+ 3
yeah, debugging is hell sometimes... just search for 'javascript debugging tips' AND: coding tip pro: debug your javascript code under water, so no one will see you crying...😁
23rd Aug 2018, 6:05 AM
SouthPoleHillbilly
SouthPoleHillbilly - avatar
+ 2
mx lst, It fixed the NULL issue, thanks. But same issue appears when the dice rolled for example 4 times and no number six was rolled, then it will give me the same error.. See changes to code line 60 to 71
22nd Aug 2018, 7:34 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
+ 1
mx lst, we'll do! Appericiate it!!👍🌴 Thanks for the tip! 😁😁
23rd Aug 2018, 11:25 AM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar