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 doesn't this pass!!

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

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>

7 Answers

Justin Olson
Justin Olson
13,792 Points

Good day! Your code is nearly perfect, you are just missing the ; after the alert. Should show like this...

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

Bob McCarty
PLUS
Bob McCarty
Courses Plus Student 16,618 Points

Thomas,

Both floor() and round() achieve the same result in that they return an integer. But the quiz expects round() instead of floor(). By convention, the nearest integer to .5 is the next highest integer.

Bob

Hi Thomas,

you've missed a semicolon at the end of the second line:

... 
alert(Math.floor(temperature))

But I think that the main problem could be your script path. Are you sure that your script is in the same directory like your index.html? Maybe it is in the js folder. Try to check it and fix the path according to your folder:

If the script.js is in the js folder your path should be:

... 
<script src="js/script.js"></script>
... 

I did htat and it still didn't work

I passed question 1 of 2 with the rounding function. problem 2 of 2 with floor method does not pass, might be a bug here is my code.

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

did not work, I tried multiple times with and without semicolons, as well as changing script src = "script.js"> </script> to <script src = "js/script.js" ></script>

I think it is a bug in the console.

Bob McCarty
PLUS
Bob McCarty
Courses Plus Student 16,618 Points

Thomas,

This answer passed for me.

var temperature = 37.5;

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