JavaScript abs() method implementation

Took 1 minutes and 30 seconds to code JavaScript abs() method. Here is the code snippet.

Code:

function abs(num) {
num2 = num * -1;
return num2;
}

document.write(abs(-4.7));

Result:

4.7

No comments:

Post a Comment

Coding for Kids

What is coding? In coding we build a program to do a specific task for us. Code: A code is a set of computer instructions and when you will ...