-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (32 loc) · 1.17 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
const testimonials = [
{ text: "I couldn't be happier with the results!", author: "John Doe" },
{ text: "Amazing service! Highly recommended.", author: "Jane Smith" },
{ text: "The best decision I've ever made!", author: "Bob Johnson" },
];
let currentTestimonial = 0;
const testimonialElem = document.getElementById("testimonial");
const authorElem = document.getElementById("author");
const prevBtn = document.getElementById("prev-btn");
const nextBtn = document.getElementById("next-btn");
function showTestimonial() {
const testimonial = testimonials[currentTestimonial];
testimonialElem.innerHTML = `"${testimonial.text}"`;
authorElem.innerHTML = `- ${testimonial.author}`;
}
function showPrev() {
currentTestimonial--;
if (currentTestimonial < 0) {
currentTestimonial = testimonials.length - 1;
}
showTestimonial();
}
function showNext() {
currentTestimonial++;
if (currentTestimonial >= testimonials.length) {
currentTestimonial = 0;
}
showTestimonial();
}
prevBtn.addEventListener("click", showPrev);
nextBtn.addEventListener("click", showNext);
showTestimonial();