-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (27 loc) · 1022 Bytes
/
index.js
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
window.onload = function() {
document.getElementById("systems-container").innerHTML = "Loading";
getSystemsFile().then((systems) => {
document.getElementById("systems-container").innerHTML = formatSystems(systems);
})
}
async function getSystemsFile() {
const response = await fetch("http://localhost:3000/systems");
const systems = await response.json();
return systems;
}
function formatSystems(systems) {
let systemsHTML = ""
systems.forEach((system) => {
systemsHTML = systemsHTML.concat(`
<div class="system-block">
<h2 class="system-title">${system.model}</h2>
<h3 class="system-OS">${system.OS}</h3>
<ul class="system-specs">
`)
system.specs.forEach((spec) => {
systemsHTML = systemsHTML.concat(`<li id="system-spec">${spec}</li>`)
})
systemsHTML = systemsHTML.concat(`</ul><span class="system-price">\$${system.price}</span></div>`)
});
return systemsHTML;
}