-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (22 loc) · 974 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
async function getWeather(){
const city = document.getElementById("nag").value;
const url = `http://localhost:4508/weather?city=${city}`;
try {
const response = await fetch(url);
const data = await response.json();
if(response.ok){
const weatherData = data.days[0];
document.getElementById("temperature").innerText = weatherData.temp + "F";
document.getElementById("weather").innerText = `Max: ${weatherData.tempmax} °F, Min: ${weatherData.tempmin} °F`;
}else{
document.getElementById('temperature').innerText = 'N/A';
document.getElementById('weather').innerText = 'N/A';
console.error('Error:', data.message);
}
} catch (error) {
document.getElementById('temperature').innerText = 'N/A';
document.getElementById('weather').innerText = 'N/A';
console.error('Error:', error);
}
}
window.onload = getWeather;