-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
76 lines (58 loc) · 2.34 KB
/
Copy pathscript.js
File metadata and controls
76 lines (58 loc) · 2.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
async function renderUsers(amount = 12) {
const data = await window.usersData.getRandomUser(amount);
const users = data?.results || [];
const container = document.getElementById('cards');
container.innerHTML = '';
for (let i = 0; i < users.length; i++) {
const u = users[i];
const card = document.createElement('article');
card.className = 'card';
const info = document.createElement('div');
info.className = 'card-info';
const name = document.createElement('h2');
name.textContent = `${u.name.first} ${u.name.last}`;
const dob = document.createElement('p');
dob.innerHTML = `DOB: ${new Date(u.dob.date).toLocaleDateString()}`;
const address = document.createElement('p');
let street = '';
let city = '';
let region = '';
let country = '';
street = `${u.location.street.number} ${u.location.street.name}`;
city = u.location.city;
region = u.location.state;
country = u.location.country;
address.innerHTML = `address: ${street}<br>${city} ${region} ${country}`;
const email = document.createElement('p');
email.innerHTML = `email: ${u.email}`;
const phone = document.createElement('p');
phone.innerHTML = `number: ${u.phone}`;
info.appendChild(name);
info.appendChild(dob);
info.appendChild(address);
info.appendChild(email);
info.appendChild(phone);
const imgsection = document.createElement('div');
imgsection.className = 'card-image';
const img = document.createElement('img');
img.src = (u.picture && u.picture.large) || '';
img.alt = `${u.name.first} ${u.name.last}`;
imgsection.appendChild(img);
card.appendChild(info);
card.appendChild(imgsection);
container.appendChild(card);
}
}
renderUsers();
const amountInput = document.getElementById('amount');
const amountLabel = document.querySelector('.usercount');
function updateAmountLabel() {
const amount = amountInput.value;
amountLabel.textContent = `${amount} users`;
}
amountInput.addEventListener('input', updateAmountLabel);
updateAmountLabel();
document.getElementById('generate').onclick = async () => {
const amount = parseInt(amountInput.value, 10);
await renderUsers(amount);
};