+ 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 Answers
+ 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