Problem with N shortcut


#1

I have a problem with the n shortcut, it keeps saying :
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.

ovar 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);

Can someone please help me?


#2

Hi Snipie1,

↑ That should be var main.

A semi-colon (;) ends the current statement. So you need to remove that.


#3

Hello! This is how should your code look like.

That must be VAR = MAIN, not OVAR
You can't put semi-colon at the end of IF statement, when you want to add ELSE IF.

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

}

$(document).ready(main);

Cheers :slightly_smiling: Hope this will help you!


#4

Thank You very much!!!
:wink:It was my problem too!