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

Why is my code not passing? It seems correct!

I'm doing https://teamtreehouse.com/library/javascript-basics-2/working-with-numbers/using-math-methods

In challenge task 2, according to me, it should work.

var temperature = 37.5;
alert(Math.floor(temperature));

But it's not!

script.js
var temperature = 37.5;

alert(Math.floor(temperature));
index.html
<!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

Hi Santosh,

Do you still have the code in from task 1? I just checked it on my end and it worked fine with the following code.

var temperature = 37.5

alert(Math.round(temperature));
alert(Math.floor(temperature));

Yes, The previous code needs to be there.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

Indeed, yes you're right, we're using 2 methods here across both tasks :)

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

The code is correct, but you need to use Math.round instead of Math.floor()

We're rounding the number up instead of down. :-)