Converting multiple variables

Greetings all, I’m a new member and just learning coding. I’m in the process of developing a web page that pulls weather API data from multiple sources. Some of the sources return data in metric. I need to convert multiple variables to empirical and use math.floor to round to single integer. The API does not have a units conversion parameter so right now I am merely adding conversion formulas to the variable definition. Clearly this is not the proper way to do this.

var iconair24 = response.hours[17].airTemperature[0].value * 9 / 5  + 32;
var iconwnsd24 = response.hours[17].windSpeed[1].value * 2.237;

Since I’m new, I am going to just work on getting the temperature conversion with a function.
Here is my current code that I have so far.

var settings = {"url": "https://api.stormglass.io/v1/weather/point?lat=40.370181&lng=-73.934193&key=e3238934-2f48-11ea-afbb-0242ac130002- 
 e3238a7e-2f48-11ea-afbb-0242ac130002","method":"GET","timeout":0,
 };

$.ajax(settings).done(function (response) {
console.log(response);

var iconair24 = response.hours[17].airTemperature[0].value * 9 / 5  + 32;

$(".iconair24").append(iconair24);

function getFahrenheitFromCelsius(celsius){return (celsius * (9 / 5)) + 32;
 }

But this where I lose how to tie in the function to my variable. Once I figure out the function, I should be able to add the math.floor to it later. Any tips would be most welcome.

Eric

Do you know how to call a function and pass it an argument? If not, I suggest you research that or better yet, check out our Basic JavaScript curriculum that will teach you this and many other things about web development with JavaScript.

var iconair24 = response.hours[17].airTemperature[0].value * 9 / 5  + 32;

Since you have already defined a function named getFahrenheitFromCelsius, you need to pass response.hours[17].airTemperature[0].value to your function. You would assign the result of the function call to iconair24.

1 Like

Thank you very much, for that info! I’ll be working in this today and will report back when I get it.