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

Tairony Campos Lozer
Tairony Campos Lozer
1,029 Points

What is wrong ?

What is missing?

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>

3 Answers

Hi there,

You're close - the challenge asks for the value to be rounded to the nearest integer. Math.floor() will round down to the nearest integer, but Math.round() will do what it's looking for - nearest integer, up or down. If you replace the method name, it should pass.

---Updated to show comment from discussion below---

Ah, so you're on Step 2 - that's the problem.

You need to keep the code from Step 1 - in challenges, you almost never want to delete code from previous steps unless it specifically tells you to. What you need here is to have both alerts:

var temperature = 37.5;
alert(Math.round(temperature));
alert(Math.floor(temperature));
Tairony Campos Lozer
Tairony Campos Lozer
1,029 Points

I was trying, but it did not work.

Would you mind copying what you're trying now? It should look like this:

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

It also occurs to me that you didn't mention which step you were on - if you're on Step 2, make sure you keep the code from Step 1 also.

Tairony Campos Lozer
Tairony Campos Lozer
1,029 Points

I can't believe it ... lol I tried everything but that. Cool =) Thank you very much

Glad you got it!

Tairony Campos Lozer
Tairony Campos Lozer
1,029 Points

I paste, the same =(

I paste var temperature = 37.5; alert (Math.round(temperature));

ERROR Bummer! Did you use the Math.floor() method?

Open an alert dialog a second time and display the temperature variable rounded downward to the nearest integer. You'll need to check the Mozilla Developer Network to find the proper Math method for this (hint: down is toward the "floor".)

Ah, so you're on Step 2 - that's the problem.

You need to keep the code from Step 1 - in challenges, you almost never want to delete code from previous steps unless it specifically tells you to. What you need here is to have both alerts:

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

I'll update my answer to reflect this - since you only had one alert(), I figured you were probably on Step 1.