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 Using Math Methods

A BUG REPORT var temperature = 37.5; alert(Math.floor(temperature)); this solution is correct but rejected

A BUG REPORT

var temperature = 37.5; alert(Math.floor(temperature));

this solution is correct but rejected

script.js
var temperature = 37.5;
alert(Math.floor(temperature));
index.html
<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

3 Answers

Umesh Ravji
Umesh Ravji
42,386 Points

Hi Yewon, Math.floor() isn't the correct answer for the first problem because it floors 37.5 to 37 when the answer is 38. That is why Math.round() is required to round 37.5 to 38.

andren
andren
28,558 Points

Your code will result in 37 and while it can be argued that it is the nearest integer it goes against the rules of rounding in math. When rounding to the nearest integer in math you round up once you get to 5 and above. So the answer should be 38.

The point of this task is to introduce the math.round() function which does mathematical rounding for you. Using that method will result in the number 38.

ahh okay i misunderstood the question, thanks ! :)