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 Create a random number

Math.round Code Challenge

I typed in the following code and it gave me a pass to the next question saying I did this right however the alert box that appears is incorrect. Why did it pass my code?

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

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

Hi Tracy,

If the challenge is passing an incorrect value then there might be an underlying error behind the code, but you don't need to worry too much about that.

Let's look at the code quickly.

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

What catches my eye is that you're passing in a float directly into the Math.Round function and then a string of 'roundedTemp' into the alert box. What you're trying to do there is pass in a reference to the Rounded Temp variable. You can do the same with temperature variable to Math.Round().

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

If you pass in a reference to the variables to these methods I believe that will work for you. :)