JavaScript floor() method implementation

Took 1 minute and 23 seconds to code JavaScript floor() method. Here is the code snippet.

Code:

num = 4.8;
function floor(num) {
x = num;
x = x - x % 1;
return x;
}

document.write(floor(num));

Result:

4

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...