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 trialStephen Parker
7,158 PointsDoes that mean that console.log( math.round(3.9)); rounds to 4?
It says if it is under .5 then it will round to 3, but does not clarify if it will go up to 4 or just stay at 3.9
2 Answers
andren
28,558 PointsThe MDN definition of Math.round states:
The Math.round() function returns the value of a number rounded to the nearest integer.
Integers are whole numbers, so anything below 3.5 would become 3, anything above would become 4.
Amber Cyr
19,699 PointsTo add to Andren's answer, there is also a function Math.floor() that rounds the number to the largest integer less than or equal to the number, so Math.floor(3.9) will give you 3.
Just thought I would point this out in case Math.floor() is better suited for your needs.