I'm trying to get data from https://wttr.in/?format=j1 to show on a webpage. I'm very new to Javascript so I hoped this would be easy but I'm struggling to get it to work, what am I doing wrong?.
<html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content= "width=device-width, initial-scale=1.0" /> </head> <body> <p id="temp"></p> </body> <script> const api_url = "https://wttr.in/?format=j1"; async function getWeather() { const response = await fetch(api_url); const data = await response.json(); const weather = data.results[0].current_condition[0]; let { temp } = weather.temp_C; document.getElementById("temp").href = "temp:" + temp; getWeather(); </script> </html>
}anywhere.resultsproperty. You want to accessdata.current_condition[0]directly.let { temp } =- those curly braces here make no sense, remove them.hrefattribute of a paragraph, that makes little sense. Make that last linedocument.getElementById("temp").innerHTML = "temp:" + temp;