• July 26, 2024

Current Weather

Loading…

Wind Speed:

// Fetch data from the Weather Company Data API fetch(apiEndpoint) .then(response => { if (!response.ok) { throw new Error(`HTTP error! Status: ${response.status}`); } return response.json(); }) .then(data => { // Extract and display temperature, humidity, and wind speed const temperature = data.observations[0].imperial.temp; const humidity = data.observations[0].humidity; const windSpeed = data.observations[0].imperial.windSpeed;

document.getElementById('temperature').innerText = `Temperature: ${temperature}°F`; document.getElementById('humidity').innerText = `Humidity: ${humidity}%`; document.getElementById('wind').innerText = `Wind Speed: ${windSpeed} mph`; }) .catch(error => console.error('Error fetching weather data:', error));

Related post