jeudi 16 février 2017

Javascript if statement says 63>542 is true

I'm doing code wars, and I cannot understand why the code below doesn't work as I want it to work.

The best is if I remove 63 it works.

function low(numbers){
      var arr = numbers.split(" ")
      var highest = numbers[0];
      for(i = 0; i < arr.length; i++){
        if(arr[i] > highest){
          console.log(arr[i] +">"+ highest)
          console.log(arr[i] > highest)
          highest = arr[i]
        }
      }
      return highest
    }

    low("4 5 29 4 0 -214 542 -64 1 -3 3 4 63 -6"); 

Aucun commentaire:

Enregistrer un commentaire