Current Weather
Loading…
Wind Speed:

// Replace 'yourStationID' with the PWS Station ID you want to retrieve data for const stationId = 'KMOINNSB1';
// API endpoint URL const apiEndpoint = `https://api.weather.com/v2/pws/observations/current?stationId=${stationId}&format=json&units=m&apiKey=${apiKey}`;
// 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));