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 trialKristóf Molnár
1,549 PointsStuck 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;
alert(Math.round(temperature));
<!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
ursaminor
11,271 PointsThe 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
1,549 PointsKristóf Molnár
1,549 PointsAye it said open an alert dialog for the SECOND time. Yeah I did replace that. Thanks a lot!