-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
83 lines (75 loc) · 2.11 KB
/
app.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
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
77
78
79
80
81
82
83
const data = [{
name: 'John Doe',
age: 32,
gender: 'male',
lookingFor: 'female',
loaction: 'Dhaka',
image: 'https://randomuser.me/api/portraits/men/82.jpg'
},
{
name: 'Jen Smith',
age: 28,
gender: 'male',
lookingFor: 'female',
loaction: 'Rajshahi',
image: 'https://randomuser.me/api/portraits/men/84.jpg'
},
{
name: 'William Johnson',
age: 36,
gender: 'female',
lookingFor: 'male',
loaction: 'Rangpur',
image: 'https://randomuser.me/api/portraits/women/45.jpg'
},
{
name: 'Nicola Tesla',
age: 18,
gender: 'female',
lookingFor: 'male',
loaction: 'Chittagong',
image: 'https://randomuser.me/api/portraits/women/23.jpg'
}
];
const profiles = profileIterator(data);
// Call first profile
nextProfile();
// Next Event
document.getElementById('next').addEventListener('click', nextProfile);
// Next profile display
function nextProfile() {
const currentProfile = profiles.next().value;
if (currentProfile !== undefined) {
document.getElementById('profileDisplay').innerHTML = `
<ul class="list-group">
<li class="list-group-item">Name: ${currentProfile.name}</li>
<li class="list-group-item">Age: ${currentProfile.age}</li>
<li class="list-group-item">Gender: ${currentProfile.gender}</li>
<li class="list-group-item">looking for: ${currentProfile.lookingFor}</li>
</ul>
`;
document.getElementById('imageDisplay').innerHTML = `
<img src="${currentProfile.image}">
`
} else {
window.location.reload();
}
}
function* profileIterator(profiles) {
for (let i = 0; i < profiles.length; i++) {
yield profiles[i];
}
}
// function profileIterator(profiles) {
// let nextIndex = 0;
// return {
// next: function () {
// return nextIndex < profiles.length ? {
// value: profiles[nextIndex++],
// done: false
// } : {
// done: true
// }
// }
// }
// }