function turnToNegative(num) { // turn to negative } | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

function turnToNegative(num) { // turn to negative }

Help me to complete the code

21st Oct 2023, 6:24 PM
Efe Daniel Aghahowa
Efe Daniel Aghahowa - avatar
7 Answers
+ 1
function turnToNegative(num) { return -Math.abs(num) }
21st Oct 2023, 7:55 PM
Efe Daniel Aghahowa
Efe Daniel Aghahowa - avatar
+ 6
if the number is larger than 0, you get the negative number by multiplying with -1
21st Oct 2023, 6:34 PM
Lisa
Lisa - avatar
+ 4
Show what you have tried. Give a COMPLETE task description.
21st Oct 2023, 6:43 PM
Lisa
Lisa - avatar
+ 2
How to link a code: Go to Code section, click +, select the programming language, insert your code, save. Come back to this thread, click +, Insert Code, sort for My Code Bits, select your code.
21st Oct 2023, 7:12 PM
Lisa
Lisa - avatar
+ 2
What is the task? You need to call the function. You need to output the result to the console.
21st Oct 2023, 7:26 PM
Lisa
Lisa - avatar
+ 1
I have tried your logic but it was not accurate
21st Oct 2023, 6:42 PM
Efe Daniel Aghahowa
Efe Daniel Aghahowa - avatar
21st Oct 2023, 7:17 PM
Efe Daniel Aghahowa
Efe Daniel Aghahowa - avatar