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

Undefined style reference

I'm working on the second project in the full stack techdegree program and am getting caught up on what I believe is a referencing error. I think my global variable may be incorrect but am unsure as it could just be the style and display reference. Any direction would be helpful, thanks in advance!!

const listItem = document.getElementsByClassName("student-item cf");
//variable to store number of names to show per page//
const perPage = 10;


const showPage = (list, page) => {
   const startIndex = (page * perPage) - perPage;
   const endIndex = page * perPage; 
   for (let i = 0; i <= list.length; i += 1) {
     let li = list[i];
     if (i >= startIndex && i < endIndex) {
      li.style.display = '';
      console.log('display');
   } else  {
      li.style.display = 'none';
      console.log('notdisplayed');
      }
   }
   console.log(list); 
}

3 Answers

Harald N
Harald N
15,843 Points

Not sure this would fix it since without the html, it is hard for me to test it myself. however you can try to set the style.display = 'block' inside the if clause, to se if that makes them visible again?

Thanks for your response! I realized afterward the HTML would probably be useful. I actually have since figured it out so yay!

Robert Manolis
STAFF
Robert Manolis
Treehouse Guest Teacher

Right on, Rachel! Nice work sorting this out. In the future, if you run into trouble with a TD project, the quickest and preferred way to get some friendly support and guidance is to reach out in Slack and share a link to your repo. If you have any trouble with any of that, please reach out to help@teamtreehouse.com. :)