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 trialjrmcintyre
4,892 PointsMath.floor command isn't working
Please help
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>
3 Answers
andren
28,558 PointsMath.floor
is not working because you changed the value of temperature
into a rounded version. You are not meant to alter the temperature
variable at all during this task. Only print it out using the round
and floor
methods. Like this:
var temperature = 37.5;
alert(Math.round(temperature));
alert(Math.floor(temperature));
I also added semicolons to your alert calls. Semicolons are not mandatory in JavaScript unless you have multiple statements on one line. So your code would have worked without them, but using them is considered a good practice.
Manpreet Singh
13,014 Pointsyou should add semicolon after alert
nico dev
20,364 PointsHi James McIntyre ,
It does! Great job.
Just remember removing the Math.round() before when you try the Math.floor().
Otherwise the Math.round() will change the temperature variable value to 38 and Math.floor() will just return 38.
Try it. It should work. It did to me.
nico dev
20,364 Pointsnico dev
20,364 PointsOops, sorry, silly of me.
I didn't check the challenge.
andren is right, James. Ignore my answer, sorry. :)