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

I need help with this.

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.

Math. ( 5 / 2)

2 Answers

Stephan Olsen
Stephan Olsen
6,650 Points

To round down an integer, you should use Math.Floor().

SRIMUGAN J
PLUS
SRIMUGAN J
Courses Plus Student 5,345 Points

Hi Alex,

You can use Math.round() method to round of the values, but sometimes didn't give the answer what you are expected. for eg Math.round(5/2) which gives answer 3 because if 5 is divided by 2 the quotient'll be 2.5 by using round() method if decimal value which is equal to .5 or more rounds the next highest value which here rounded as 3.

Instead of using Math.round you can use Math.floor() or Math.ceil() depending upon your requirement. If you need further details go through this link

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round

Hope this helps.