Question: Follow the following tutorial: https://www.youtube.com/watch?v=SjLJ8Dyuywg To retrieve JSON data from the open weather service. If the temp is colder than 50, use a light blue
Follow the following tutorial:
https://www.youtube.com/watch?v=SjLJ8Dyuywg
To retrieve JSON data from the open weather service.
If the temp is colder than 50, use a light blue to indicate the cold,
if the temp is hot, make the background a yellow
Display the weather information on the top of the screen
*********I have completed the code below BUT need help changing celsius to fahrenheit when clicking get weather data. Also if anyone can touch it up a little to make it more appealing?
$(document).ready(function () {
$('#btnGetWeather').click(function () {
var resultElement = $('#resultDiv');
resultElement.html('');
var requestData = $('#txtCity').val() + ',' + $('#txtCountry').val();
$.ajax({
url: 'http://api.openweathermap.org/data/2.5/weather',
method: 'get',
data: { q: requestData, appid:'2b92ac90c161a8b52a86175509113de9', units:'metric'},
dataType: 'json',
success: function (response) {
if (response.message != null) {
resultElement.html(response.message);
}
else {
if(response.main.temp < 50) {
$('body').css('background-color', '#2aa3fb');
} else {
$('body').css('background-color', '#e0e419');
}
resultElement.html('Temp: ' + response.main.temp + '
' + 'Weather: ' + response.weather[0].main + '
' + 'Description: ' + response.weather[0].description);
}
},
error: function (err) {
alert(err);
}
});
});
});
| City | |
| Country |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
