Skip to content

Commit 95cdad5

Browse files
committed
switch to local images
1 parent 6f4c947 commit 95cdad5

File tree

2 files changed

+61
-8
lines changed

2 files changed

+61
-8
lines changed

03-reviews/final/app.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ const reviews = [
44
id: 1,
55
name: 'susan smith',
66
job: 'web developer',
7-
img: 'https://images2.imgbox.com/e0/57/qI5bbwvg_o.jpeg',
7+
img: 'https://www.course-api.com/images/people/person-1.jpeg',
88
text: "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",
99
},
1010
{
1111
id: 2,
1212
name: 'anna johnson',
1313
job: 'web designer',
14-
img: 'https://images2.imgbox.com/2e/6e/JAMvTZ56_o.jpeg',
14+
img: 'https://www.course-api.com/images/people/person-2.jpeg',
1515
text: '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.',
1616
},
1717
{
1818
id: 3,
1919
name: 'peter jones',
2020
job: 'intern',
21-
img: 'https://images2.imgbox.com/56/88/oJvFN3l5_o.jpeg',
21+
img: 'https://www.course-api.com/images/people/person-4.jpeg',
2222
text: '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.',
2323
},
2424
{
2525
id: 4,
2626
name: 'bill anderson',
2727
job: 'the boss',
28-
img: 'https://images2.imgbox.com/8b/1c/vwWNTsCd_o.jpeg',
28+
img: 'https://www.course-api.com/images/people/person-3.jpeg',
2929
text: '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. ',
3030
},
3131
];

03-reviews/setup/app.js

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,81 @@ const reviews = [
44
id: 1,
55
name: 'susan smith',
66
job: 'web developer',
7-
img: 'https://images2.imgbox.com/e0/57/qI5bbwvg_o.jpeg',
7+
img: 'https://www.course-api.com/images/people/person-1.jpeg',
88
text: "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",
99
},
1010
{
1111
id: 2,
1212
name: 'anna johnson',
1313
job: 'web designer',
14-
img: 'https://images2.imgbox.com/2e/6e/JAMvTZ56_o.jpeg',
14+
img: 'https://www.course-api.com/images/people/person-2.jpeg',
1515
text: '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.',
1616
},
1717
{
1818
id: 3,
1919
name: 'peter jones',
2020
job: 'intern',
21-
img: 'https://images2.imgbox.com/56/88/oJvFN3l5_o.jpeg',
21+
img: 'https://www.course-api.com/images/people/person-4.jpeg',
2222
text: '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.',
2323
},
2424
{
2525
id: 4,
2626
name: 'bill anderson',
2727
job: 'the boss',
28-
img: 'https://images2.imgbox.com/8b/1c/vwWNTsCd_o.jpeg',
28+
img: 'https://www.course-api.com/images/people/person-3.jpeg',
2929
text: '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. ',
3030
},
3131
];
32+
// select items
33+
const img = document.getElementById('person-img');
34+
const author = document.getElementById('author');
35+
const job = document.getElementById('job');
36+
const info = document.getElementById('info');
37+
38+
const prevBtn = document.querySelector('.prev-btn');
39+
const nextBtn = document.querySelector('.next-btn');
40+
const randomBtn = document.querySelector('.random-btn');
41+
42+
// set starting item
43+
let currentItem = 0;
44+
45+
// load initial item
46+
window.addEventListener('DOMContentLoaded', function () {
47+
const item = reviews[currentItem];
48+
img.src = item.img;
49+
author.textContent = item.name;
50+
job.textContent = item.job;
51+
info.textContent = item.text;
52+
});
53+
54+
// show person based on item
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+
// show next person
63+
nextBtn.addEventListener('click', function () {
64+
currentItem++;
65+
if (currentItem > reviews.length - 1) {
66+
currentItem = 0;
67+
}
68+
showPerson(currentItem);
69+
});
70+
// show prev person
71+
prevBtn.addEventListener('click', function () {
72+
currentItem--;
73+
if (currentItem < 0) {
74+
currentItem = reviews.length - 1;
75+
}
76+
showPerson(currentItem);
77+
});
78+
// show random person
79+
randomBtn.addEventListener('click', function () {
80+
console.log('hello');
81+
82+
currentItem = Math.floor(Math.random() * reviews.length);
83+
showPerson(currentItem);
84+
});

0 commit comments

Comments
 (0)