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 trialShaun Wetzel
9,085 PointsHelp with Math.floor()
completed task one, went onto task to and repeated basically what I did in task one except this time it asked to round down to the nearest integer with Math.floor(). I went on to do so and after pressing check work it tells me I need to have my 'Math.floor()' look like 'Math.floor(temperature)' which I did. I don't see what I did wrong.
var temperature = 37.5
temperature = Math.round(temperature);
alert(temperature);
temperature = Math.floor(temperature);
alert(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
David Kaneshiro Jr.
29,247 PointsWhat happened was that you saved the value returned from Math.round() to the original temperature variable, which means that the value in temperature is 38 after using Math.round(). So when you used temperature again as a parameter in Math.floor() you were rounding the value of 38 instead of the original value of 37.5.
Shaun Wetzel
9,085 PointsShaun Wetzel
9,085 PointsThank you that makes a lot of sense now!
David Kaneshiro Jr.
29,247 PointsDavid Kaneshiro Jr.
29,247 PointsYou're welcome.