Search code examples
javascriptvariablesintegernegative-number

how to convert -1 to 1 with javascript?


how to convert -1 to 1 with javascript ?

var count = -1; //or any other number -2 -3 -4 -5 ...

or

var count = 1; //or any other number 2 3 4 5 ...

result should be

var count = 1; //or any other number 2 3 4 5 ...

Solution

  •  count = Math.abs(count)
     // will give you the positive value of any negative number