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 trialTairony Campos Lozer
1,029 PointsWhat is wrong ?
What is missing?
var temperature = 37.5;
alert (Math.floor(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
Katie Wood
19,141 PointsHi 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
1,029 PointsI can't believe it ... lol I tried everything but that. Cool =) Thank you very much
Katie Wood
19,141 PointsGlad you got it!
Tairony Campos Lozer
1,029 PointsI 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".)
Katie Wood
19,141 PointsAh, 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.
Tairony Campos Lozer
1,029 PointsTairony Campos Lozer
1,029 PointsI was trying, but it did not work.
Katie Wood
19,141 PointsKatie Wood
19,141 PointsWould you mind copying what you're trying now? It should look like this:
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.