-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (34 loc) · 1.02 KB
/
script.js
File metadata and controls
39 lines (34 loc) · 1.02 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
const url = "https://jsonplaceholder.typicode.com/users/"
function bringData() {
fetch(url)
.then((response) => response.json())
.then((json) => giveData(json))
}
trying()
function giveData(jsonData) {
// console.log(jsonData)
jsonData.forEach((user) => {
document.querySelector(".data").innerHTML += `
<a href="profile.html?userId=${user.id}">
<article>
<h3>${user.name}</h3>
<p><strong>Telephono:</strong> ${user.phone}</p>
<p><strong>User name:</strong> ${user.username}</p>
<p><strong>Email:</strong> ${user.email}</p>
</article>
</a>
`
})
}
// same function as bringdata() but using async/await with try/catch syntax
async function trying(){
try {
let response = await fetch(url)
let data = await response.json()
console.log(data)
giveData(data)
}
catch(err) {
throw "something happened on the way to heaven"
}
}