Skip to content

Commit af51108

Browse files
projeto mostrando como acessar itens de um objeto
1 parent 950ac90 commit af51108

2 files changed

Lines changed: 86 additions & 1 deletion

File tree

‎3-reviews/setup/app.js‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,57 @@ 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+
// selecionar itens
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+
53+
let currentItem = 0;
54+
55+
// carregando o item inicial
56+
window.addEventListener("DOMContentLoaded", function () {
57+
showPerson();
58+
});
59+
60+
//mostrar pessoa baseado no item
61+
function showPerson() {
62+
const item = reviews[currentItem];
63+
img.src = item.img;
64+
author.textContent = item.name;
65+
job.textContent = item.job;
66+
info.textContent = item.text;
67+
}
68+
69+
// mostrar proxima pessoa
70+
71+
nextBtn.addEventListener('click', function () {
72+
currentItem++;
73+
if (currentItem > reviews.length - 1) {
74+
currentItem = 0;
75+
}
76+
showPerson();
77+
});
78+
79+
//mostrar pessoa anterior
80+
81+
prevBtn.addEventListener("click", function () {
82+
currentItem--;
83+
if (currentItem < 0) {
84+
currentItem = reviews.length -1;
85+
}
86+
showPerson();
87+
});
88+
89+
// show random version
90+
randomBtn.addEventListener("click", function () {
91+
currentItem = Math.floor(Math.random() * reviews.length);
92+
showPerson();
93+
});

‎3-reviews/setup/index.html‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,38 @@
1313
<link rel="stylesheet" href="styles.css" />
1414
</head>
1515
<body>
16-
<h1>review project</h1>
16+
<main>
17+
<section class="container">
18+
<!--title-->
19+
<div class="title">
20+
<h2>Our reviews</h2>
21+
<div class="underline"></div>
22+
</div>
23+
<!--review-->
24+
<article class="review">
25+
<div class="img-container">
26+
<img src="./person-1.jpeg" id="person-img" alt=""/>
27+
</div>
28+
<h4 id="author">sara jones</h4>
29+
<p id="job">ux designer</p>
30+
<p id="info">Lorem ipsum dolor sit amet consectetur adipisicing elit.
31+
Vitae nulla veritatis cupiditate iste laborum mollitia ad laudantium ea,
32+
necessitatibus eaque illum, corrupti esse exercitationem.
33+
Illo repellat asperiores hic nihil a.</p>
34+
<!--prev next button-->
35+
<div class="button-container">
36+
<button class="prev-btn">
37+
<i class="fas fa-chevron-left"></i>
38+
</button>
39+
<button class="next-btn">
40+
<i class="fas fa-chevron-right"></i>
41+
</button>
42+
</div>
43+
<!--random button-->
44+
<button class="random-btn">suprise me</button>
45+
</article>
46+
</section>
47+
</main>
1748
<!-- javascript -->
1849
<script src="app.js"></script>
1950
</body>

0 commit comments

Comments
 (0)