The n shortcut 2


#1

Hi there! Don't understand what's wrong with this ):

https://www.codecademy.com/courses/web-beginner-en-4hxyb/0/9?content_from=make-an-interactive-website%3Ajquery-events#

This is the error message I get:
Oops, try again. It looks like the n key isn't moving to the next article. Remember to remove the 'current' class from currentArticle and place it on nextArticle.


var main=function(){
$('.article').click(function() {
    $('.article').removeClass('current');
    $('.description').hide();

 $(document).keypress(function(event) {
  if(event.which === 111) {
    $('.current').children('.description').toggle();
  }
  else if(event.which === 110) {
      var currentArticle = $('current');
      var nextArticle = currentArticle.next();
      currentArticle.removeClass('current');
      nextArticle.addClass('current');
}
});
    
    $(this).addClass('current');
    $(this).children('.description').show();
});
};
    $(document).ready(main);


Thanks for Your help!


#2

Hi your $(document).keypress(function(event) ({..}); shouldn't be inside the $('.article').click(function() {...}); so it should be like that

var main = function() {

    $('.article').click(function() { 
        ......
    })
    $(document).keypress(function(event) { 
        .....
    });
};
$(document).ready(main);

then this line

var currentArticle = $('current');

you should save in currentArticle the class current so you need the dot before it like that

var currentArticle = $('.current');

#3

Thanks a lot WizMarco! (:


#4

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.