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 trialsv
1,244 PointsWhat am I doing wrong?
I am using this and it look correct and even gives me the alert box with 37 in it.
'''var temperature = 37.5; alert(Math.floor(temperature));'''
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>
2 Answers
Joe Cochran
18,249 PointsThis question is asking you to "round to the nearest integer." The Math.floor() method always rounds down, not to the nearest integer. If you use the Math.round() method instead, it will round up to 38.
alert(Math.round(temperature));
I tested and the challenge only accepts Math.round(), not Math.floor() or Math.ceil().
sv
1,244 PointsJoe,
Yep - that was it ! very strange.
Much thanks for quick replies!
-Sig
sv
1,244 Pointssv
1,244 PointsJoe - much thanks for quick reply.
It is a two part question - the first part is round down and the second question, according to the hint is expecting floor (and it seems to work because I get a dialog box showing 37).
Here is a screenshot showing the issue: http://note.io/1C80ren
-Sig
Joe Cochran
18,249 PointsJoe Cochran
18,249 PointsOh! The challenge engine does not like it when you remove a line from a past step! Instead of removing the Math.round, add a second alert with the math.floor instead!