-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
48 lines (43 loc) · 1.34 KB
/
script.js
File metadata and controls
48 lines (43 loc) · 1.34 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
(function () {
const example = document.getElementById('example')
const cw1 = document.getElementById('cw1')
const cw2 = document.getElementById('cw2')
const cw3 = document.getElementById('cw3')
const answer = document.getElementById('answer')
example.addEventListener("click", function () {
fetch('https://jsonplaceholder.typicode.com/posts')
.then(response => response.json())
.then(array => {
console.log(array)
answer.innerHTML = JSON.stringify(array);
})
})
cw1.addEventListener("click", function () {
fetch('https://jsonplaceholder.typicode.com/posts')
.then(response => response.json())
.then(posts => {
console.log(posts)
let html = '<h2>Lista postów</h2>';
posts.forEach(post => {
html += `
<div>
<h3>Post #${post.id}: ${post.title}</h3>
<p><strong>User ID:</strong> ${post.userId}</p>
<p>${post.body}</p>
</div>
`;
});
answer.innerHTML = html;
})
.catch(error => {
console.error('Błąd:', error);
answer.innerHTML = '<p style="color: red;">Wystąpił błąd podczas pobierania postów.</p>';
})
})
cw2.addEventListener("click", function () {
//TODO
})
cw3.addEventListener("click", function () {
//TODO
})
})();