Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Working With Numbers Review Working with Numbers

Manveer Sandhu
PLUS
Manveer Sandhu
Courses Plus Student 1,389 Points

complete the code

Complete the following code so that the results of this math operation are rounded down to the nearest integer. For example, .6 will be rounded to 0. question : math.______(5/2)

1 Answer

Brandon Benefield
Brandon Benefield
7,739 Points

Well, it depends on if you want to round up or down.

In your example, 5 / 2 will equal 2.5

If you do not have any prejudice over which way your number rounds too, you can just use

Math.round(5/2) // returns 3

Math.ceil(5/2) // also returns 3, but Math.ceil() will round up

Math.floor(5/2) // returns 2, floor rounds down

Hope this helps.