Skip to content

Commit 2d3beed

Browse files
committed
finished project review №3
1 parent 0a607ba commit 2d3beed

2 files changed

Lines changed: 106 additions & 18 deletions

File tree

‎3-reviews/setup/app.js‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,61 @@ 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+
41+
//select items
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+
//set starting item
52+
let currentItem = 0;
53+
54+
//load initial item
55+
window.addEventListener("DOMContentLoaded", function () {
56+
const item = reviews[currentItem];
57+
//load initial item-- img.src = item.img;
58+
//load initial item--- author.textContent = item.name;
59+
//load initial item--- job.textContent = item.job;
60+
//load initial item--- info.textContent = item.text;
61+
showPerson(currentItem);
62+
});
63+
64+
//show person based on item+add function
65+
function showPerson() {
66+
const item = reviews[currentItem];
67+
img.src = item.img;
68+
author.textContent = item.name;
69+
job.textContent = item.job;
70+
info.textContent = item.text;
71+
}
72+
73+
//show next person
74+
nextBtn.addEventListener("click", function () {
75+
currentItem++;
76+
if (currentItem > reviews.length - 1) {
77+
currentItem = 0;
78+
};
79+
showPerson();
80+
})
81+
82+
83+
//show prev person
84+
prevBtn.addEventListener("click", function () {
85+
currentItem--;
86+
if (currentItem < 0) {
87+
currentItem = reviews.length - 1;
88+
};
89+
showPerson();
90+
})
91+
92+
//show random person
93+
randomBtn.addEventListener("click", function () {
94+
currentItem = Math.floor(Math.random() * reviews.length)
95+
console.log(currentItem);
96+
showPerson();
97+
})

‎3-reviews/setup/index.html‎

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,50 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8" />
5-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>Starter</title>
7-
<!-- font awesome -->
8-
<link
9-
rel="stylesheet"
10-
href="./fontawesome-free-5.12.0-web/css/all.min.css"
11-
/>
12-
<!-- styles -->
13-
<link rel="stylesheet" href="styles.css" />
14-
</head>
15-
<body>
16-
<h1>review project</h1>
17-
<!-- javascript -->
18-
<script src="app.js"></script>
19-
</body>
20-
</html>
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Starter</title>
8+
<!-- font awesome -->
9+
<link rel="stylesheet" href="./fontawesome-free-5.12.0-web/css/all.min.css" />
10+
<!-- styles -->
11+
<link rel="stylesheet" href="styles.css" />
12+
</head>
13+
14+
<body>
15+
<main>
16+
<div class="container">
17+
<div class="title">
18+
<h2>our reviews</h2>
19+
<div class="underline"></div>
20+
</div>
21+
<article class="review">
22+
<div class="img-container">
23+
<img src="./person-1.jpeg" id="person-img" alt="">
24+
</div>
25+
<h4 id="author">sara jones</h4>
26+
<p id="job">ux designer</p>
27+
<p id="info">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
28+
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex
29+
ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat
30+
nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim
31+
id est laborum.</p>
32+
<!--prev next buttons-->
33+
<div class="button-container">
34+
<button class="prev-btn">
35+
<i class="fas fa-chevron-left"></i>
36+
</button>
37+
<button class="next-btn">
38+
<i class="fas fa-chevron-right"></i>
39+
</button>
40+
<!--random button-->
41+
<btn class="random-btn">surprise me</btn>
42+
</div>
43+
</article>
44+
</div>
45+
</main>
46+
<!-- javascript -->
47+
<script src="app.js"></script>
48+
</body>
49+
50+
</html>

0 commit comments

Comments
 (0)