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 trialGanta Hemanth
6,460 Pointsfirst step not passing error in math object challenge of js
This is the code but it is saying first task not passing. I cant find the error
var temperature = 37.5;
alert(Math.round(temperature));
temperature += 1;
alert(Math.round(temperature));
<!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>
Ganta Hemanth
6,460 Pointsthe math object challenge.
1 st task
For this Code Challenge you need to use JavaScript's Math methods. Open an alert dialog and display the temperature variable rounded to the nearest integer.
2nd task
Open an alert dialog a second time and display the temperature variable rounded downward to the nearest integer (hint: down is toward the "floor".)
Ian Hattendorf
7,715 PointsIt helps if you can post the tasks in your questions so those reading don't have to go searching for them. Something like 'First step (round the temperature and alert the user to its new value) not passing...' for example.
Ganta Hemanth
6,460 Points@Ian Hattendorf
I did it now.. Thanks for mentioning it.
8 Answers
Ian Hattendorf
7,715 PointsYou don't need to increment the temperature by 1 here to pass the second task, it's asking you to take the 'floor' of the temperature. This is a mathematical function that essentially rounds down. JavaScript provides this as Math.floor(x)
, see here for more. You should end up with something like:
alert(Math.floor(temperature));
Ganta Hemanth
6,460 PointsThank You for the answer.
Shawn Flanigan
Courses Plus Student 15,815 PointsGanta,
If you're just trying to pass the first task, you've gone a bit too far. The first two lines of code are plenty to pass the first task. It looks like you may have passed it, then read it again and tried to pass the same challenge with a higher temperature. Remove your last two lines of code and check it again.
Ganta Hemanth
6,460 Pointsi passed the first task. But i am not able to pass the second task which is
Open an alert dialog a second time and display the temperature variable rounded downward to the nearest integer (hint: down is toward the "floor".)
Thanks for replying
Shawn Flanigan
Courses Plus Student 15,815 PointsAlright, so...for the second task, you'll want to round the temperature
variable down. They give you a hint here...you'll want to use the Math.floor()
method. This method takes a number and rounds it down to the nearest integer. This would look something like:
Math.floor(temperature);
You'll then want to put the result in an alert box, just as you did in the first step, so...
alert(Math.floor(temperature));
There's no need to add 1 to it, as you have in line 3 of your code.
Hope that makes sense.
Daniel Rego
7,956 PointsI've had this same issue. Anyone able to figure it out?
var temperature= 37.5 alert(Match.round(37.5) -- this works on the first step.
One the second step for rounding down, you should just have to change "round" to "floor" correct? This isn't working for me and causes the first task for fail every time. Anyone have any suggestions?
Ian Hattendorf
7,715 PointsYou should be creating a new alert with the floor of the temperature, not modifying the first one.
Daniel Rego
7,956 PointsI've had this same issue. Anyone able to figure it out?
var temperature= 37.5 alert(Match.round(37.5) -- this works on the first step.
One the second step for rounding down, you should just have to change "round" to "floor" correct? This isn't working for me and causes the first task for fail every time. Anyone have any suggestions?
Shawn Flanigan
Courses Plus Student 15,815 PointsDaniel,
Are you changing your first line of code to do the second task? You should be writing a second line of code below it...and yes, the second line of code will look just like the first, but using the Math.floor() method.
Shawn Flanigan
Courses Plus Student 15,815 PointsApparently answering forum questions on my phone just isn't quite fast enough. Good job, Ian.
Daniel Rego
7,956 PointsMuch appreciated Ian.
Brett Burky
3,895 PointsThe one thing that gets me is that I resisted coming in here to look at the answer. However instead I watched the videos over 3 times, not ONCE was any of this mentioned in the videos.
If we are to study the videos and perform the tasks wouldn't it make sense if it was from what we watched? I can kind of get that we should look in the MDN for answers, but that is after the fact and now something that I will take into consideration.
Not knocking the course or treehouse, love them both, I just researched for 30 minutes again for something in a place that I would never find the answer.
Eric Cantu
1,889 PointsThey are trying to get you to think like a Programmer... A lot of the job is using google and other resources to figure things out.
ttaleg
9,830 Pointsi have this and it says the 1st answer is no longer valid
var temperature = 37.5
alert(Math.round(temperature)) alert(Math.down(temperature))
Shawn Flanigan
Courses Plus Student 15,815 Pointsttaleg,
.down
isn't a valid method on the Math object. They give you a pretty good hint in the question when they say that down is toward the "floor". You'll want to use the floor
method, like so:
alert(Math.floor(temperature))
Hope that helps.
Frank Ruiz
15,558 PointsFor anyone having this issue, what fixed it for me was adding a ";" after "var temperature = 37.5"
Either I deleted it and didn't realize it, or TreeHouse removed it intentionally in order to allow us to check for bugs :)
Ian Hattendorf
7,715 PointsIan Hattendorf
7,715 PointsWhat are the tasks?