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

Ben Brenton
Ben Brenton
266 Points

Code Challenge: Syntax Error?

I am currently trying to complete a code challenge in the numbers section of JS. The following code should give me an alert showing a rounded down version of a decimal number:

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

Where am I going wrong with this? I checked MDN and I can't see where I might have made an error.

2 Answers

Hey ! you just have to call the alert dialog two times.

var temperature = 37.5
alert(Math.round(temperature));
alert(Math.floor(temperature));
Ben Brenton
Ben Brenton
266 Points

Thank you Ayoub AIT IKEN this solved my issue.

Grant G
Grant G
19,934 Points

With your code, you should get the alert box with rounded to floor temperature variable.

But why are you assigning call of alert box to temperature variable?

After that call temperature will get value of undefined, since it is the return value of alert function.

Just call it like:

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

yeah but the challenge is asking a double alert ( from Task 1 ) if she does it one time, she will have a bummer telling the first task doesnt seem to work ! other than that, you re totally right Grant Gasparyan