Skip to content
Advertisement

which one is bigger?! a problem in my js code

I write a js code to determine which number is bigger but the result is not perfect! when I input two number with same digit numbers, the result is correct. For example when I input “2” and “3” the result is “3” but when I input “2” in first field and “55” in the second field, the result is “2”.
Thank you in advance.
sorry for my weak English.

JavaScript
JavaScript

Advertisement

Answer

Document.getElementById() returns “String” type value and comparison between two string will act differently. Better convert those string types to integer.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement