-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
80 lines (72 loc) · 2.07 KB
/
index.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
// Every person's review
const reviews = [
{
name: 'Haley Burrell',
image: 'retrato-1.jpg',
job: 'Lawyer',
review: 'Best Portal for Files, Billing and Communication with clients.'
},
{
name: 'Vincent Wilson',
image: 'retrato-2.jpg',
job: 'Entrepreneur',
review: 'Excellent solution for files-sharing and eSignatures.'
},
{
name: 'Clarence Donaldson',
image: 'retrato-3.jpg',
job: 'Engineer',
review: 'By far the best designed client portal product.'
},
{
name: 'Chloe Griffin',
image: 'retrato-4.jpg',
job: 'Graphic Designer',
review: 'Messaging, file-sharing, and billing in one place!'
},
{
name: 'Rose Miller',
image: 'retrato-5.jpg',
job: 'Front-end Developer',
review: 'Amazing white label file sharing & eSignature solution.'
}
];
// Variables to select the DOM elements
const person = document.getElementById('name');
const image = document.getElementById('image');
const job = document.getElementById('job');
const review = document.querySelector('#opinion p');
const btns = document.querySelectorAll('.btn');
// Variable of Index
let index = 0;
// Shows the review
function showReview() {
const item = reviews[index];
person.textContent = item.name;
image.src = item.image;
job.textContent = item.job;
review.textContent = item.review;
}
// Load initial review
window.addEventListener('DOMContentLoaded', function () {
showReview();
});
// Function of all the buttons
btns.forEach(btn => {
btn.addEventListener('click', function () {
const btnClass = btn.classList;
if (btnClass.contains('prev')) {
index--;
} else if (btnClass.contains('next')) {
index++;
} else {
index = Math.floor(Math.random() * reviews.length);
}
if (index < 0) {
index = reviews.length - 1;
} else if (index >= reviews.length) {
index = 0;
}
showReview();
})
});