CodeWars Blog #1
Aishe Ibrahim

Aishe Ibrahim @aisheibrahim

About: Software Engineer

Location:
Raleigh, North Carolina
Joined:
May 17, 2022

CodeWars Blog #1

Publish Date: Aug 29 '23
0 0

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

Comments 0 total

    Add comment