-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
65 lines (58 loc) · 2.44 KB
/
script.js
File metadata and controls
65 lines (58 loc) · 2.44 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
let data = [];
let cv;
let currentIndex = 0;
window.addEventListener('DOMContentLoaded', async () => {
try {
const res = await fetch('data.json');
data = await res.json();
cv = cvIterator(data);
nextCV();
} catch (error) {
console.error("Failed to load data:", error);
}
});
function cvIterator(profiles) {
let nextIndex = 0;
return {
next: function () {
return nextIndex < profiles.length ?
{ value: profiles[nextIndex++], done: false } :
{ done: true }
}
};
}
document.getElementById('next').addEventListener('click', nextCV);
function nextCV() {
let currentProfile = cv.next().value;
let image = document.getElementById('image');
let profile = document.getElementById('profile');
let message = document.getElementById('mssg');
let progressBar = document.getElementById('progressBar');
if (currentProfile === undefined) {
message.innerHTML = `<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>No more profiles! You'll be redirected to the home page.</strong>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>`;
setTimeout(() => {
message.innerHTML = '';
window.location.reload();
}, 1500);
return;
}
image.innerHTML = `<img src="${currentProfile.image}" alt="Profile Image" class="img-fluid rounded-circle rounded-img">`;
profile.innerHTML = `
<ul class="list-group">
<li class="list-group-item"><strong>Name:</strong> ${currentProfile.name}</li>
<li class="list-group-item"><strong>Age:</strong> ${currentProfile.age}</li>
<li class="list-group-item"><strong>Email:</strong> ${currentProfile.email}</li>
<li class="list-group-item"><strong>Language:</strong> ${currentProfile.language}</li>
<li class="list-group-item"><strong>Framework:</strong> ${currentProfile.framework}</li>
<li class="list-group-item"><strong>Experience:</strong> ${currentProfile.experience} years</li>
<li class="list-group-item"><strong>CPI:</strong> ${currentProfile.cpi}</li>
</ul>
`;
// Update progress bar
const progress = Math.round((++currentIndex / data.length) * 100);
progressBar.style.width = `${progress}%`;
progressBar.textContent = `${progress}%`;
}