I need a help with this..Where is my mistake?


#1

"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." I need a help with this..Where is my mistake?

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

$(this).addClass('current');
$(this).children('.description').show();
});
};

$(document).keypress(function(event) {
if(event.which===111) {
$('.description').hide();
$('.current').children('.description').toggle();
else if (event.which===110) {
var currentArticle=$('.current');
var nextArticle=currentArticle.next();

        currentArticle.removeClass('current');
        nextArticle.addClass('current');
      }) ; 
    };

$(document).ready(main);

};


N shortcut not working
#2

@sakalic,
The curly-brackets-{ } are used to encapsulate a so-called a code-block
in which you have =code= should stand together.....

var main = function() {
     //=main= Function =code-block=
}

or

if ( condition ) {
    //IF =code-block=
}
else if ( condition ) {
  //ELSE-IF =codeblock=
}

==============================================

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

      $(this).addClass('current');
      $(this).children('.description').show(); 
   });
//}; should be removed!!! this would end the =main= code-block !!

   $(document).keypress(function(event) {
      if(event.which===111) {
          //$('.description').hide();
          $('.current').children('.description').toggle();
      } //you forgot to close the IF code-block
      else if (event.which===110) {
         var currentArticle=$('.current');
         var nextArticle=currentArticle.next();
         currentArticle.removeClass('current');
         nextArticle.addClass('current');
      } //you forgot to close the ELSE-IF codeblock
    }) ; 
}; //here you close the =main= function code-block

// the =main= function will be excuted if the jQuery-READY flag has been set....
$(document).ready(main);

//}; this UFCCB an unidentified flying closing-curly-bracket !!!

#3

Ok,it works. Thank you very much!!


#4

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