JavaScript JavaScript Basics Working With Numbers Using Math Methods

Christopher Floyd
PRO
Christopher Floyd
Pro Student 2,546 Points

Can't seem to get off this question....

Am i missing something here? :/ Everything looks correct but, it keeps feeding me the "Bummer" response. Thank you!

script.js
var temperature = 37.5;
temperature = alert(Math.round(temperature));
temperature = alert(Math.floor(temperature));
index.html
<!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>

4 Answers

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 44,827 Points

By assigning alert to temperature you are losing the original value of temperature = 37.5. The challenge just asks for the alert statements themselves.

Christopher Floyd
PRO
Christopher Floyd
Pro Student 2,546 Points

Bummer: Did you give the Math.floor() method the variable temperature like this Math.floor(temperature)?...... is the response i keep getting today.

i believe it has something to do with the platform. bases on the error response, everything looks to be in order. it worked fine yesterday the way it's posted here. the original value of the variable shouldn't be the issue, since it tells you to change the value" Open an alert dialog a second time and display the temperature variable rounded downward to the nearest integer."

I changed the value using the Math.round() method anyways in the first question. so, I don't think that's the issue. Thank you!

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 44,827 Points

math.round() returns the rounded value but doesn't change the original argument. To see this try the following code:

var temperature = 37.5;
alert(Math.round(temperature));
console.log(temperature);
alert(Math.floor(temperature));
console.log(temperature);

In order to change the value you would need an assignment:

temperature = Math.round(temperature)

Since alert doesn't return anything in your code you are passing a value of undefined to Math.floor()

Christopher Floyd
PRO
Christopher Floyd
Pro Student 2,546 Points

It makes sense now. That would make sense why the first time I wasn't getting the error but, the second time I was. i suppose i was doing it right yesterday....which is why i repeat until it completely makes sense. so, thank you!