-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
26 lines (24 loc) · 1.03 KB
/
script.js
File metadata and controls
26 lines (24 loc) · 1.03 KB
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
document.addEventListener('DOMContentLoaded', function() {
// Replace 'YOUR_API_KEY' with your actual API key from WeatherAPI.com
const apiKey = '5b842f67d2msh1fad4478870c15ep1ac4c1jsn6b5cee70fdae';
const city = 'TEXAS';
// Construct the API request URL
const apiUrl = `https://weatherapi-com.p.rapidapi.com/current.json?q=${city}`;
// Fetch weather data from the API
fetch(apiUrl, {
method: 'GET',
headers: {
'X-RapidAPI-Key': apiKey,
'X-RapidAPI-Host': 'weatherapi-com.p.rapidapi.com'
}
})
.then(response => response.json())
.then(data => {
// Update the table with the fetched data
document.getElementById('local').textContent = data.location.localtime;
document.getElementById('name').textContent = data.location.name;
document.getElementById('temp_f').textContent = data.current.temp_f;
document.getElementById('text').textContent = data.current.condition.text;
})
.catch(error => console.error(error));
});