You have to know more rigorously data type. replace function is operating on string data type. Your a1 is somewhat an integer. In this case, why not multiply by (-1) to make it positive?! If you are at a school, you've to ask your tutor.
[tt]
//a1=a1*(-1);
//or if you want a contrived twist
a1=parseInt(a1.toString().replace(/-/,""),10);
[/tt]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.