Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Project 2 - Pagination. First Item shows undefined.

Hi everyone,

I've been stuck with pagination but slowly making some progress. it's almost the result that I want my showPage() function to display but the first item shows undefined.

Can you please help me out?

const perPage = 10;
let studentList = document.querySelector(".student-list");
let html;

let showPage = (arrayObjects, page) => {
  let startIndex = (page * perPage) - perPage;
  let endIndex = (page * perPage);

  for (let i = 0; i < arrayObjects.length; i++){
    if(i >= startIndex && i < endIndex){
      let items  = arrayObjects[i]
      html += `
      <li class="student-item cf">
      <div class="student-details">
      <img class="avatar" src="${items.picture.thumbnail}" alt="Profile Picture">
      <h3>${items.name.first} ${items.name.last}</h3>
      <span class="email">${items.email}</span>
      </div>
      <div class="joined-details">
      <span class="date">Joined ${items.registered.date}</span>
      </div>
      </li>`
    }
    studentList.innerHTML = html;
    console.log(html)
  }
}
showPage(data,1);