hi, How do I fetch and display the weather for several cities? Now that I only get one city, I would like to show the we

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

hi, How do I fetch and display the weather for several cities? Now that I only get one city, I would like to show the we

Post by answerhappygod »

hi,
How do I fetch and display the weather for several cities? Now that
I only get one city, I would like to show the weather from
different cities simultaneously. I can figure out how to loop the
results. Some suggestions?
function weatherBalloon( cityID ) {
var key = 'APIKEY';
fetch('https://api.openweathermap.org/data/2.5/weather?id='
+ cityID+ '&appid=' + key)
.then(function(resp) { return resp.json() }) // Convert data
to json
.then(function(data) {
drawWeather(data); //
Call drawWeather
})
.catch(function() {
// catch any errors
});
}
function drawWeather( d ) {
var celcius =
Math.round(parseFloat(d.main.temp)-273.15);
var fahrenheit =
Math.round(((parseFloat(d.main.temp)-273.15)*1.8)+32);

document.getElementById('description').innerHTML
= d.weather[0].description;
document.getElementById('temp').innerHTML =
celcius + '°';
document.getElementById('location').innerHTML =
d.name;
}
window.onload = function() {
weatherBalloon( 886842 );
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply