9. The n shortcut 2


#1

Can someone please help me here?
Here is my code:

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();
            }


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

                    currentArticle.removeClass('current');
                    nextArticle.addClass('current');
                   }
            $('.current').children('.description').toggle();
        }

});

$(document).ready(main);

The instructions is:

Inside the else if statement:

Select the current article using the '.current' selector. Save this in a new variable named currentArticle
Select the next article using currentArticle.next(). Save this in a new variable named nextArticle
Remove the 'current' class from currentArticle using .removeClass()
Add the 'current' class to nextArticle using .addClass()
Click on any article, and then press the n key to see your new shortcut!

The error says:

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.

Thanks in advance!


#2

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) {
      $('.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);

I believe this should be it, you had some double code and errors, nothing too big, this should work.


#3

I praise you:innocent::innocent::innocent::innocent::innocent::innocent::pray::pray::pray::pray::pray::pray::pray::pray:. Thanks so much.
Edit: the innocent came by itself.


#4

Hi! I'm wondering where this line came from and what it serves? It was the only thing missing from my block and I'm not sure where I missed it. Thanks :slightly_smiling:


#5

@angela That line hides all HTML elements with the description class.

BTW, you should probably change your username, since right now it shows your email address.


#6

Thanks for mentioning that-- I noticed it when my post went up. I just had a ton of trouble changing it but I think it worked...
And thanks for you response.


#7

@zystvan explained it. If you need any more help on this topic, feel free to ask here or send me a message. I'll gladly help as much as I can.