-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
25 lines (24 loc) · 1.08 KB
/
scripts.js
File metadata and controls
25 lines (24 loc) · 1.08 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
// Fetching data from SpaceX API for upcoming space missions
document.addEventListener('DOMContentLoaded', () => {
const missionsDiv = document.getElementById('missions-data');
const nasaApiUrl = 'https://kauai.ccmc.gsfc.nasa.gov/DONKI/WS/get/CME?startDate=yyyy-MM-dd&endDate=yyyy-MM-dd'; // SpaceX API for upcoming launches
fetch(nasaApiUrl)
.then(response => response.json())
.then(data => {
let missionsHtml = '';
data.slice(0, 5).forEach(mission => {
missionsHtml += `
<div class="mission">
<h3>${mission.name}</h3>
<p>Date: ${new Date(mission.date_utc).toLocaleDateString()}</p>
<p>Rocket: ${mission.rocket}</p>
</div>
`;
});
missionsDiv.innerHTML = missionsHtml;
})
.catch(error => {
missionsDiv.innerHTML = '<p>Failed to fetch missions data.</p>';
console.error('Error fetching data:', error);
});
});