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

GITEX Dubai Talk by Saion Gupta and Saiasmi Gupta

Good morning, everyone. I'm Saion Gupta, the Founder of 10xCoderKids and the Guinness World Record holder for the youngest computer prog...