Dark Mode
Enable Console
inverseNum(number);
/*
Inverse the number from positive to negative, or vice versa
*/
inverseNum(15);
// -15
inverseNum(-8);
// 8
Solution by - Need4Swede
function inverseNum(number) {
// Multiply number by two, and subtract it by its initial value to get its inverse
number = number - (number * 2);
// Returns the value of number
return number;
}
Alternatively, you can write it like this...
function inverseNum(number) {
return(-number);
}
Try it yourself - Codewars Source