The if else on N key


#1

else if(event.which === 110) {
  var currentArticle = $('.current');
  var nextArticle = currentArticle.next();

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

   This is what the help code tells you to insert, here is what my code looks like:

var main = function() {
 $('.article').click(function() {
     $('.article').removeClass('current');
     $('.description').hide();
    
    $(this).addClass('current'); 
    $(this).children('.description').show();
 });
 
 $(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');
 });
}

$(document).ready(main);

I have searched for the answer for the last hour. I have tried all sorts of things... I kinda feel like giving up!

Can someone please help me figure out how to get past this?


#2

@cozy2963,

The IF ELSE-IF statement parts
both have their code-blocks which are encapsulated in a pair of curly-brackets-{ }
like

if(event.which === 111) {
   //IF code-block
   $('.current').children('.description').toggle();
}
else if(event.which === 110) {
   //ELSE-IF code-block
   var currentArticle = $('.current');
   var nextArticle = currentArticle.next();

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

#3

Thank you! That worked.