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 trial

JavaScript JavaScript Basics (Retired) Working With Numbers Using Math Methods

Math.floor command isn't working

Please help

var temperature = 37.5;
temperature = Math.round(temperature);
temperature = Math.floor(temperature);
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
<script src="script.js"></script>

3 Answers

28,558 Points

Math.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;

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.

nico dev
nico dev
20,364 Points

Oops, sorry, silly of me.

I didn't check the challenge.

andren is right, James. Ignore my answer, sorry. :)

Manpreet Singh
Manpreet Singh
13,014 Points

you should add semicolon after alert

nico dev
nico dev
20,364 Points

Hi 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.