-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsript.js
More file actions
60 lines (49 loc) · 1.8 KB
/
Copy pathsript.js
File metadata and controls
60 lines (49 loc) · 1.8 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function commitInput() {
// Get the input value
const inputValue = document.getElementById('searchField').value;
if (inputValue) {
window.location.href = './pages/collection/collection.html?query=' + encodeURIComponent(inputValue)
} else {
window.alert("Please eter search criterias.")
}
}
window.onload = function () {
getTimeForStarts()
}
const rows = 5
const columns = 2
const rocketStarts = Array.from({ length: rows }, () => Array(columns).fill(undefined));
function getTimeForStarts() {
const url = 'https://fdo.rocketlaunch.live/json/launches/next/5'
fetch(url)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
let entries = data.result
console.log(entries)
let i = 0
entries.forEach(entry => {
rocketStarts[i][0] = entry.launch_description
i++
});
const first = document.getElementById('firstStart')
const second = document.getElementById('secondStart')
const third = document.getElementById('thirdStart')
const fourth = document.getElementById('fourthStart')
const fifth = document.getElementById('fifthStart')
if (first && second && third && fourth && fifth) {
first.innerText = rocketStarts[0][0]
second.innerText = rocketStarts[1][0]
third.innerText = rocketStarts[2][0]
fourth.innerText = rocketStarts[3][0]
fifth.innerText = rocketStarts[4][0]
}
})
.catch(error => {
console.error('Error during API call:', error);
});
}