7 months ago
18 lines395 B
async function forecast(city) { | |
const res = await fetch(`/api/weather?city=${encodeURIComponent(city)}`); | |
if (!res.ok) throw new Error(`HTTP ${res.status}`); | |
return res.json(); | |
} | |
| |
async function main() { | |
try { | |
const f = await forecast("Lisbon"); | |
console.log(f.temperature); | |
} catch (err) { | |
console.error(err.message); | |
} | |
} | |
| |
main(); | |
| |
// Questions? Ask in the course forum. |