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

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