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

James Cobbett
James Cobbett
1,468 Points

Why is my code not working?

I do not understand why this line of code is not working? This is what is states on MDN, am I missing something?

script.js
var temperature=37.5;
Math.floor(temperature);
alert(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

Andreas Nyström
Andreas Nyström
8,887 Points

You need to alert the whole thing. Right now you're only alerting temperature which still holds 37.5.

So for the first challenge they want you to alert a rounded number and the second challenge they want you to round down and alert this.

var temperature = 37.5;
// First challenge, alerting the rounded temperature
alert(Math.round(temperature));

// Second challenge, alerting the rounded down temperature
alert(Math.floor(temperature));

Hopefully this clears some things up, if not - ask again. Happy coding!

James Cobbett
James Cobbett
1,468 Points

Oh i get it now, thanks alot !