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 trialElizabeth Bentivegna
1,433 PointsI'm trying alert(Math.floor(temperature)); - is this not correct? I'm getting "Bummer: Did you use Math.round()?
I'm getting an error when I try and submit this but when I hit preview I get an alert with 37 as expected.
var temperature = 37.5;
alert(Math.floor(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>
3 Answers
Steven Parker
231,269 PointsYou're expecting 37 because you're using "floor". But the instructions say "rounded to the nearest integer". So 38 would actually be the correct answer, which is what you'd get using "round".
Your first method choice might be more appropriate for task 2.
Unsubscribed User
Front End Web Development Techdegree Student 33,900 PointsHi Elizabeth,
in this challenge you are asked to use Math.round and not Math.floor.
The difference is: Math.floor always rounds down ( 3.3 -> 3 ; 3.5 -> 3 ; 3.7 -> 3) while Math.round rounds to the nearest integer (3.3 -> 3 ; 3.5 -> 4).
So, with 37.5 the methods produce different results.
Makes sense?
Happy coding!
Nils
PS: You can upvote my post and/or mark as "best answer" (at the bottom of my post) if it helped you. :-)
Elizabeth Bentivegna
1,433 PointsFor challenge two you are specifically asked to use the floor, which is what I'm having trouble with. "Open an alert dialog a second time and display the temperature variable rounded downward to the nearest integer. You'll need to check the Mozilla Developer Network to find the proper Math method for this (hint: down is toward the "floor".)"
Unsubscribed User
Front End Web Development Techdegree Student 33,900 PointsYes, for the second one it should be Math.floor.
Arrachael Miller
6,058 Pointspart 1 answer alert(Math.round(temperature));
part 2 answer var temperature = 37.5; alert(Math.round(temperature)); alert(Math.floor(temperature));
Steven Parker
231,269 PointsMy understanding is that Treehouse discourages posting explicit answers without explanations. I like to think most students actually prefer a few hints and solving for themselves anyway.
Elizabeth Bentivegna
1,433 PointsElizabeth Bentivegna
1,433 PointsThis is for task two. βRounded downward to the nearest integerβ would be 37, right?
Steven Parker
231,269 PointsSteven Parker
231,269 PointsDownwards would be 37, which is correct for task 2; but you must also observe the other instruction "Important: In each task of this code challenge, the code you write should be added to the code from the previous task."
So the task 1 alert code should remain as-is while you add the new one after it.
Elizabeth Bentivegna
1,433 PointsElizabeth Bentivegna
1,433 PointsThat was it, I didn't realize I HAD to add it afterward. I did so and it worked. Thanks.