Use fetch function to read the weather details from openweathermap.org and display the details like city, min-temp, max-temp, humidity on the webpage for a given city
Tue Apr 22 2025 18:32:24 GMT+0000 (Coordinated Universal Time)
Saved by
@fsd
async function getWeather(){
let city=document.getElementById('city').value;
const response= await fetch(`https://api.openweathermap.org/data/2.5/forecast?q=${city}&appid=6a86468ac81fa36a5565acaaa9f651b5`)
const data = await response.json()
const {list}=data
var temparray=new Array()
for(let i=0;i<list.length;i=i+8){
const {dt_txt,main:{temp,temp_min,temp_max}}=list[i]
temparray.push(temp);
console.log(`Date:${dt_txt},Temperature:${temp},Minimum_temp:${temp_min},Max_temp:${temp_max}`)
}
}
content_copyCOPY
Comments