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

Gabriel Ward
Gabriel Ward
20,222 Points

unexpected end of input

I'm trying to use this piece of code to make my main-nav a sticky nav, but in the console it says that there's an 'unexpected end of input' on line 17. I can't see where the problem is. Any tips would be greatly appreciated

// Create a clone of the menu, right next to original.
$('.main-navigation').addClass('original').clone().insertAfter('.menu').addClass('cloned').css('position','fixed').css('top','0').css('margin-top','0').css('z-index','500').removeClass('original').hide();

scrollIntervalID = setInterval(stickIt, 10);


function stickIt() {

  var orgElementPos = $('.original').offset();
  orgElementTop = orgElementPos.top;               

  if ($(window).scrollTop() >= (orgElementTop)) {
    // scrolled past the original position; now only show the cloned, sticky element.
//UNEXPECTED INPUT IS SOMWHERE AROUND HERE
    // Cloned element should always have same left position and width as original element.     
    orgElement = $('.original');
    coordsOrgElement = orgElement.offset();
    leftOrgElement = coordsOrgElement.left;  
    widthOrgElement = orgElement.css('width');
    $('.cloned').css('left',leftOrgElement+'px').css('top',0).css('width',widthOrgElement).show();
    $('.original').css('visibility','hidden');
  } else {
    // not scrolled past the menu; only show the original menu.
    $('.cloned').hide();
    $('.original').css('visibility','visible');
  }
}
Trevor Waddell
Trevor Waddell
17,643 Points

Where did you define these variables:

coordsOrgElement = orgElement.offset();
leftOrgElement = coordsOrgElement.left;  
widthOrgElement = orgElement.css('width');

try adding the 'var' keyword in front, so that the interpreter can know what they are.

Gabriel Ward
Gabriel Ward
20,222 Points

Still no luck with those changes!