Fix issue where comparing strings instead of numbers in JavaScript