How to fix JavaScript bug in is valid number example?