fixed typo
improved damage error checking

by using self explanatory built-in JavaScript function