|
1 | 1 | // local reviews data |
2 | 2 | const reviews = [ |
3 | | - { |
4 | | - id: 1, |
5 | | - name: "susan smith", |
6 | | - job: "web developer", |
7 | | - img: |
8 | | - "https://res.cloudinary.com/diqqf3eq2/image/upload/v1586883334/person-1_rfzshl.jpg", |
9 | | - text: |
10 | | - "I'm baby meggings twee health goth +1. Bicycle rights tumeric chartreuse before they sold out chambray pop-up. Shaman humblebrag pickled coloring book salvia hoodie, cold-pressed four dollar toast everyday carry", |
11 | | - }, |
12 | | - { |
13 | | - id: 2, |
14 | | - name: "anna johnson", |
15 | | - job: "web designer", |
16 | | - img: |
17 | | - "https://res.cloudinary.com/diqqf3eq2/image/upload/v1586883409/person-2_np9x5l.jpg", |
18 | | - text: |
19 | | - "Helvetica artisan kinfolk thundercats lumbersexual blue bottle. Disrupt glossier gastropub deep v vice franzen hell of brooklyn twee enamel pin fashion axe.photo booth jean shorts artisan narwhal.", |
20 | | - }, |
21 | | - { |
22 | | - id: 3, |
23 | | - name: "peter jones", |
24 | | - job: "intern", |
25 | | - img: |
26 | | - "https://res.cloudinary.com/diqqf3eq2/image/upload/v1586883417/person-3_ipa0mj.jpg", |
27 | | - text: |
28 | | - "Sriracha literally flexitarian irony, vape marfa unicorn. Glossier tattooed 8-bit, fixie waistcoat offal activated charcoal slow-carb marfa hell of pabst raclette post-ironic jianbing swag.", |
29 | | - }, |
30 | | - { |
31 | | - id: 4, |
32 | | - name: "bill anderson", |
33 | | - job: "the boss", |
34 | | - img: |
35 | | - "https://res.cloudinary.com/diqqf3eq2/image/upload/v1586883423/person-4_t9nxjt.jpg", |
36 | | - text: |
37 | | - "Edison bulb put a bird on it humblebrag, marfa pok pok heirloom fashion axe cray stumptown venmo actually seitan. VHS farm-to-table schlitz, edison bulb pop-up 3 wolf moon tote bag street art shabby chic. ", |
38 | | - }, |
| 3 | + { |
| 4 | + id: 1, |
| 5 | + name: "susan smith", |
| 6 | + job: "web developer", |
| 7 | + img: |
| 8 | + "https://res.cloudinary.com/diqqf3eq2/image/upload/v1586883334/person-1_rfzshl.jpg", |
| 9 | + text: |
| 10 | + "I'm baby meggings twee health goth +1. Bicycle rights tumeric chartreuse before they sold out chambray pop-up. Shaman humblebrag pickled coloring book salvia hoodie, cold-pressed four dollar toast everyday carry", |
| 11 | + }, |
| 12 | + { |
| 13 | + id: 2, |
| 14 | + name: "anna johnson", |
| 15 | + job: "web designer", |
| 16 | + img: |
| 17 | + "https://res.cloudinary.com/diqqf3eq2/image/upload/v1586883409/person-2_np9x5l.jpg", |
| 18 | + text: |
| 19 | + "Helvetica artisan kinfolk thundercats lumbersexual blue bottle. Disrupt glossier gastropub deep v vice franzen hell of brooklyn twee enamel pin fashion axe.photo booth jean shorts artisan narwhal.", |
| 20 | + }, |
| 21 | + { |
| 22 | + id: 3, |
| 23 | + name: "peter jones", |
| 24 | + job: "intern", |
| 25 | + img: |
| 26 | + "https://res.cloudinary.com/diqqf3eq2/image/upload/v1586883417/person-3_ipa0mj.jpg", |
| 27 | + text: |
| 28 | + "Sriracha literally flexitarian irony, vape marfa unicorn. Glossier tattooed 8-bit, fixie waistcoat offal activated charcoal slow-carb marfa hell of pabst raclette post-ironic jianbing swag.", |
| 29 | + }, |
| 30 | + { |
| 31 | + id: 4, |
| 32 | + name: "bill anderson", |
| 33 | + job: "the boss", |
| 34 | + img: |
| 35 | + "https://res.cloudinary.com/diqqf3eq2/image/upload/v1586883423/person-4_t9nxjt.jpg", |
| 36 | + text: |
| 37 | + "Edison bulb put a bird on it humblebrag, marfa pok pok heirloom fashion axe cray stumptown venmo actually seitan. VHS farm-to-table schlitz, edison bulb pop-up 3 wolf moon tote bag street art shabby chic. ", |
| 38 | + }, |
39 | 39 | ]; |
| 40 | + |
| 41 | +// Get elements |
| 42 | +const img = document.getElementById("person-img"); |
| 43 | +const author = document.getElementById("author"); |
| 44 | +const job = document.getElementById("job"); |
| 45 | +const info = document.getElementById("info"); |
| 46 | + |
| 47 | +const prevBtn = document.querySelector(".prev-btn"); |
| 48 | +const nextBtn = document.querySelector(".next-btn"); |
| 49 | +const randomBtn = document.querySelector(".random-btn"); |
| 50 | + |
| 51 | +let currentPerson = 0; |
| 52 | + |
| 53 | +function loadPerson(person) { |
| 54 | + const item = reviews[person]; |
| 55 | + img.src = item.img; |
| 56 | + author.textContent = item.name; |
| 57 | + job.textContent = item.job; |
| 58 | + info.textContent = item.text; |
| 59 | +} |
| 60 | + |
| 61 | +window.addEventListener("DOMContentLoaded", function () { |
| 62 | + loadPerson(currentPerson); |
| 63 | +}); |
| 64 | + |
| 65 | +prevBtn.addEventListener("click", function () { |
| 66 | + currentPerson--; |
| 67 | + if (currentPerson < 0) { |
| 68 | + currentPerson = reviews.length - 1; |
| 69 | + } |
| 70 | + |
| 71 | + loadPerson(currentPerson); |
| 72 | +}); |
| 73 | +nextBtn.addEventListener("click", function () { |
| 74 | + currentPerson++; |
| 75 | + if (currentPerson > reviews.length - 1) { |
| 76 | + currentPerson = 0; |
| 77 | + } |
| 78 | + loadPerson(currentPerson); |
| 79 | +}); |
| 80 | + |
| 81 | +randomBtn.addEventListener("click", function () { |
| 82 | + const randomPerson = Math.floor(Math.random() * reviews.length); |
| 83 | + loadPerson(randomPerson); |
| 84 | +}); |
0 commit comments