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 trialGarth Miller
7,567 Pointsif alert(Math.floor(temperature)); is NaN then how do i get around this
just trying to get around this problem
var temperature = alert(Math.round(37.5));
alert(Math.floor(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>
1 Answer
furkan
11,733 Pointsvar temperature = alert(Math.round(37.5)); alert(Math.floor(temperature));
I believe you are assigning a string to the temperature variable when you use alert to store the 37.5. So instead of saying:
Var temperature = alert(Math.round(37.5));
Try removing the alert and just store the following for the temperature variable:
var temperature = Math.round(37.5);
Then the rest of the code should be fine once you have ammended this part.
Anthony Collier
101 PointsAnthony Collier
101 PointsI found by removing the
Math.round()
method from thetemperature
variable and doing this below actually functions correctly.Based off your code, I went with this:
But line 1 displays
38
and line 2 displaysNaN
becausealert(Math.round(37.5))
is not a number. Am I interpretting this correctly?