Closed idleherb closed 7 years ago
try ... catch ... finally:
finally should only be used if in ANY case (try or catch) you want to do something in finally -> not here, because you already return in try block -> return in catch
why "null" as return value? should be 0 (no long words found)
Thank you for the hint. You nailed it!!! I should read more carefully ;)!
@agareis just as a comment:
Current code:
try {
return str.match(/[\w0-9]{7,}/gi).length;
}
catch (error){
console.log("Something went wrong ", error);
return 0;
Possible alternative, without using try... catch:
var match = str.match(/[\w0-9]{7,}/gi);
if (match === null) { // No long words were found
return 0;
}
return match.length;
@agareis In general, "Something went wrong" is also not a good error message. It is a sign that you don't know what went wrong ;) What went wrong in the above case is that the regular expression did not return any matches because there were no long words in the text.
You have a strong point here! And again I fell into your trap ;)! Lesson learned: If I plagiarise I should be aware of the consequences hearing and feeling from my dear mentor :D!!!
Error Description
No matter what input the textbox has, no errors should appear in the console -> add error handling for such cases.
Bonus: when user focuses textarea and starts to enter characters in the textbox, "Infinity" appears -> maybe a maximum value or a text explaining what is happening would be better