Round Up in JavaScript

Level 128 keystrokes

Uses Math.ceil() to round 2.1 up and prints 3.

JavaScript code

// Math.ceil() returns the smallest integer greater than or equal to the number
// Any fraction rounds up, so 2.1 becomes 3; Math.ceil(-2.1) is -2
1console.log(Math.ceil(2.1));

Output

3
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • .× 3
  • (× 2
  • )× 2
  • ;× 1

More JavaScript examples at level 1

← JavaScript typing practice