Positive Number to Negative Number in JavaScript? Positive Number to Negative Number in JavaScript? javascript javascript

Positive Number to Negative Number in JavaScript?


Math.abs(num) => Always positive-Math.abs(num) => Always negative

You do realize however, that for your code

if($this.find('.pdxslide-activeSlide').index() < slideNum-1){ slideNum = -slideNum }console.log(slideNum)

If the index found is 3 and slideNum is 3,
then 3 < 3-1 => false
so slideNum remains positive??

It looks more like a logic error to me.


The reverse of abs is Math.abs(num) * -1.


The basic formula to reverse positive to negative or negative to positive:

i - (i * 2)