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 trialJorge Valerio
Front End Web Development Techdegree Graduate 24,696 PointsNot really sure what im i doing wrong...
Im having trouble with this problem, any help is really apreciated. Thanks
var temperature = 37.5
var temperature = Math.round(temperature);
alert(temperature);
var temperature = Math.floor(temperature);
alert(temperature);
2 Answers
Jason Anello
Courses Plus Student 94,610 PointsHi Jorge,
It doesn't cause any problems to use var
more than once but it's not necessary and you'll never see that done.
Your problem though is that you're changing the value of temperature. You're taking the return value of the round
function and assigning it back to temperature. Now, temperature is 38 and no longer 37.5.
So, you alert
the 38 but then you're stuck passing 38 into the floor function which returns back 38.
However, the challenge is expecting you to pass the original temperature into floor
so that you would get 37 back.
Instead of assigning the value back to temperature you can alert the value directly like this:
var temperature = 37.5
alert(Math.round(temperature)); // This will alert 38 and temperature will still be 37.5
The alert for task 2 would be done similarly.
Lonnie Wibberding
18,318 PointsOnce you declare the 'temperature' variable with the keyword 'var' the first time you should just use 'temperature' to refer to it after that. No need to use 'var' more than once.
Jorge Valerio
Front End Web Development Techdegree Graduate 24,696 PointsJorge Valerio
Front End Web Development Techdegree Graduate 24,696 PointsThan you so much for your explanation.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsYou're welcome, Jorge.