+ 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
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 š
+ 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...š
+ 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
+ 1
mx lst, we'll do! Appericiate it!!šš“
Thanks for the tip! šš