-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
68 lines (60 loc) · 1.67 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
const data = [
{
name: 'John Doe',
age: 32,
gender: 'male',
lookingfor: 'female',
location: 'Boston MA',
image: 'https://randomuser.me/api/portraits/men/82.jpg'
},
{
name: 'Jen Smith',
age: 26,
gender: 'female',
lookingfor: 'male',
location: 'Miami FL',
image: 'https://randomuser.me/api/portraits/women/82.jpg'
},
{
name: 'William Johnson',
age: 38,
gender: 'male',
lookingfor: 'female',
location: 'Lynn MA',
image: 'https://randomuser.me/api/portraits/men/83.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">Location: ${currentProfile.location}</li>
<li class="list-group-item">Preference: ${currentProfile.gender} looking for ${currentProfile.lookingfor}</li>
</ul>
`;
document.getElementById('imageDisplay').innerHTML = `<img src="${currentProfile.image}">`;
} else {
// No more profiles
window.location.reload();
}
}
// Profile Iterator
function profileIterator(profiles) {
let nextIndex = 0;
return {
next: function() {
return nextIndex < profiles.length ?
{ value: profiles[nextIndex++], done: false } :
{ done: true }
}
};
}