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

Kristóf Molnár
Kristóf Molnár
1,549 Points

Stuck with math.round and math.floor in Javascript, could you guys help me please?

Hi guys! I'm a bit stuck with this task, could you help me? :)

Question: For this Code Challenge you need to use JavaScript's Math methods. Open an alert dialog and display the temperature variable rounded to the nearest integer.

My answer: var temperature = 37.5; alert(Math.floor(temperature));

In the preview it works like a charm. However, when I click "Check work" it says: Bummer: Did you use the Math.round() method?
No, I did not, cause the task was to use the floor one. If I change my script to "Math.round" like the error message suggested, it now says: Bummer: Did you use the Math.floor() method?

So what am I supposed to do now? What's the real problem here?

Thanks a lot for the answer!

var temperature = 37.5;
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
<script src="script.js"></script>

1 Answer

The first task says "display the temperature variable rounded to the nearest integer", so you need to use Math.round(), not Math.floor(). For the second task, you need to add another alert() method below that using Math.floor(). Sounds like maybe you replaced the first method instead of adding another one.

Kristóf Molnár
Kristóf Molnár
1,549 Points

Aye it said open an alert dialog for the SECOND time. Yeah I did replace that. Thanks a lot!