JavaScript ceil() method implementation

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

Code:

num = 4.4;
function ceil(num) {
x = num;
x = x - x % 1;
x = x + 1;
return x;
}

document.write(ceil(num));

Result:

5

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