Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!

script.js
var temperature = 37.5;
alert(Math.round(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>

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!