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

Ray Edison Refundo
Ray Edison Refundo
3,798 Points

display the temparature variable rounded downward to the nearest integer (hint: down is toward the "floor".)

I'm not exactly sure what's wrong with my code, can anyone elaborate what I did wrong?

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

Tony Nguyen
Tony Nguyen
24,934 Points

Waddup Ray!

Try entering your answer without making your alert boxes variables.

Ray Edison Refundo
Ray Edison Refundo
3,798 Points

Oh, haha I got kind of confused I passed the exercise with

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

and it worked but, yeah I realized I shouldn't even have to add the same variable towards the alerts. Thanks though!

It's only asking you to use the alert method. Since the temperature variable has been created, you don't need to create it again.

Try this, I've removed "var temperature =" from the second and third lines. You should notice that alert still functions without being assigned to the temperature variable.

var temperature = 37.5
alert(Math.round(temperature));
alert(Math.floor(temperature));
Ray Edison Refundo
Ray Edison Refundo
3,798 Points

Thanks for giving an elaborate explanation :), I understand now what I did wrong.