Skip to content

Commit b4f7bfc

Browse files
committed
Adding functionality to the buttons reviews.
1 parent 208d749 commit b4f7bfc

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

3-reviews/setup/app.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,44 @@ const reviews = [
3737
"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. ",
3838
},
3939
];
40+
const img = document.getElementById("person-img");
41+
const author = document.getElementById("author");
42+
const job = document.getElementById("job");
43+
const info = document.getElementById("info");
44+
45+
const prevBtn = document.querySelector(".prev-btn");
46+
const nextBtn = document.querySelector(".next-btn");
47+
const randomBtn = document.querySelector(".random-btn");
48+
49+
let currentItem = 0;
50+
51+
window.addEventListener('DOMContentLoaded', function(){
52+
showPerson(currentItem);
53+
});
54+
55+
function showPerson(person){
56+
const item = reviews[person];
57+
img.src = item.img;
58+
author.textContent = item.name;
59+
job.textContent = item.job;
60+
info.textContent = item.text;
61+
}
62+
63+
nextBtn.addEventListener('click', function(){
64+
currentItem++;
65+
if(currentItem > reviews.length - 1) {
66+
currentItem = 0;
67+
}
68+
showPerson(currentItem);
69+
});
70+
prevBtn.addEventListener('click', function(){
71+
currentItem--;
72+
if(currentItem < 0){
73+
currentItem = reviews.length - 1;
74+
}
75+
showPerson(currentItem);
76+
});
77+
randomBtn.addEventListener('click', function(){
78+
currentItem = Math.floor(Math.random() * reviews.length);
79+
showPerson(currentItem);
80+
});

3-reviews/setup/index.html

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,32 @@
1414
<link rel="stylesheet" href="styles.css" />
1515
</head>
1616
<body>
17-
<h1>review project</h1>
17+
<main>
18+
<section class="container">
19+
<div class="title">
20+
<h2>our reviews</h2>
21+
<div class="underline"></div>
22+
</div>
23+
<article class="review">
24+
<div class="img-container">
25+
<img src="./person-1.jpeg" id="person-img" alt="">
26+
</div>
27+
<h4 id="author">sara jones</h4>
28+
<p id="job">ux designer</p>
29+
<p id="info">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quas molestias ut at rerum, recusandae mollitia laudantium ea fugiat nulla minima eum dolores explicabo? Consequuntur, numquam sint vel doloribus pariatur eaque?</p>
30+
<div class="button-container">
31+
<button class="prev-btn">
32+
<i class="fas fa-chevron-left"></i>
33+
</button>
34+
<button class="next-btn">
35+
<i class="fas fa-chevron-right"></i>
36+
</button>
37+
</div>
38+
<button class="random-btn">surprise me</button>
39+
</article>
40+
</section>
41+
</main>
42+
1843
<!-- javascript -->
1944
<script src="app.js"></script>
2045
</body>

0 commit comments

Comments
 (0)