-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
43 lines (35 loc) · 1.06 KB
/
app.js
File metadata and controls
43 lines (35 loc) · 1.06 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
// when a user clicks the button we fetch some data
const fetchBtn = document.getElementById('fetch');
const filterBtn = document.getElementById('filter');
const content = document.getElementById('content');
const input = document.getElementById('text');
let items;
fetchBtn.addEventListener('click', function () {
// get some data from an API
window.fetch('https://fakestoreapi.com/products').then((res) => {
res.json().then((data) => {
console.log(data);
items = data;
for (let i = 0; i < data.length; i++) {
// add this to the page
content.innerHTML += `
<div>
<h1>${data[i].title}</h1>
<img src=${data[i].image}
</div>
`;
}
});
});
});
filterBtn.addEventListener('click', function () {
// set the screen to empty
content.innerHTML = '';
// get the value from the input
const val = input.value;
// filter the items by the input
// TODO: can you figure out the filtering logic?
});
/**
* PS - check out parsity.io/dev30 if you want to learn JS the right way;)
*/