DEV Community

Aishe Ibrahim
Aishe Ibrahim

Posted on

CodeWars Blog #1

The problem:

In this simple assignment you are given a number and have to make it negative. But maybe the number is already negative?

This problem is asking for a program that will take a number and return the same number as a negative. If the number already entered is negative, then it negates the program.

To counteract that issue, Math.abs() method will first take the number and convert it to its absolute form (if it's negative, it will return positive) then multiply by (-1).

The Solution:

function makeNegative(num){
  return Math.abs(num) * -1
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)