brickbobed
brickbobed

Reputation: 179

Greater than operator not working with if statement

if statement with greater than condition returning true even though value is not greater than.

im having it return the values and it returns "no 54765>100000". hoping someone can help me locate where my mistake is.

if (rev[2] > value) {
    document.getElementById("answer").innerHTML =
      "no " + rev[2] + ">" + value;
  } else {
    document.getElementById("answer").innerHTML = "yes";
  }

Upvotes: 0

Views: 1655

Answers (2)

ldtcoop
ldtcoop

Reputation: 680

You can also use Number to convert strings of digits into numbers with the added bonus of it working for integers and floats. For example:

Number('100') // returns 100
Number('3.14') // returns 3.14

Upvotes: 0

JC Hernández
JC Hernández

Reputation: 807

Try this:

if (parseFloat(rev[2]) > parseFloat(value)) {

Upvotes: 3

Related Questions