Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 34 additions & 27 deletions 03-reviews/final/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,55 @@
const reviews = [
{
id: 1,
name: 'susan smith',
job: 'web developer',
img: 'https://www.course-api.com/images/people/person-1.jpeg',
name: "susan smith",
job: "web developer",
img: "https://www.course-api.com/images/people/person-1.jpeg",
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",
},
{
id: 2,
name: 'anna johnson',
job: 'web designer',
img: 'https://www.course-api.com/images/people/person-2.jpeg',
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.',
name: "anna johnson",
job: "web designer",
img: "https://www.course-api.com/images/people/person-2.jpeg",
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.",
},
{
id: 3,
name: 'peter jones',
job: 'intern',
img: 'https://www.course-api.com/images/people/person-4.jpeg',
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.',
name: "peter jones",
job: "intern",
img: "https://www.course-api.com/images/people/person-4.jpeg",
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.",
},
{
id: 4,
name: 'bill anderson',
job: 'the boss',
img: 'https://www.course-api.com/images/people/person-3.jpeg',
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. ',
name: "bill anderson",
job: "the boss",
img: "https://www.course-api.com/images/people/person-3.jpeg",
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. ",
},
// {
// id: 5,
// name: "anirudh negi",
// job: "engineer",
// img: "https://www.course-api.com/images/people/person-10.jpeg",
// 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. ",
// },
];
// select items
const img = document.getElementById('person-img');
const author = document.getElementById('author');
const job = document.getElementById('job');
const info = document.getElementById('info');
const img = document.getElementById("person-img");
const author = document.getElementById("author");
const job = document.getElementById("job");
const info = document.getElementById("info");

const prevBtn = document.querySelector('.prev-btn');
const nextBtn = document.querySelector('.next-btn');
const randomBtn = document.querySelector('.random-btn');
const prevBtn = document.querySelector(".prev-btn");
const nextBtn = document.querySelector(".next-btn");
const randomBtn = document.querySelector(".random-btn");

// set starting item
let currentItem = 0;

// load initial item
window.addEventListener('DOMContentLoaded', function () {
window.addEventListener("DOMContentLoaded", function () {
const item = reviews[currentItem];
img.src = item.img;
author.textContent = item.name;
Expand All @@ -60,24 +67,24 @@ function showPerson(person) {
info.textContent = item.text;
}
// show next person
nextBtn.addEventListener('click', function () {
nextBtn.addEventListener("click", function () {
currentItem++;
if (currentItem > reviews.length - 1) {
currentItem = 0;
}
showPerson(currentItem);
});
// show prev person
prevBtn.addEventListener('click', function () {
prevBtn.addEventListener("click", function () {
currentItem--;
if (currentItem < 0) {
currentItem = reviews.length - 1;
}
showPerson(currentItem);
});
// show random person
randomBtn.addEventListener('click', function () {
console.log('hello');
randomBtn.addEventListener("click", function () {
console.log("hello");

currentItem = Math.floor(Math.random() * reviews.length);
showPerson(currentItem);
Expand Down