How can I check the positive number in Javascript and return the opposite?
Example, pass to a function or enter into the prompt:
1: -1 14: -14
UPD: the code turned out to be with an error - plus changed to negative now changes as needed
function opposite(number) { if (number < 0) { return -(number) } else { return +(number) } } console.log(opposite(-1));
-1, get the opposite. - Visman