9. n Shortcut 2 – assistance required


#1

I've got to a stage where I'm struggling on the this section, can some advise?

I've got two error messages:

Uncaught SyntaxError: Unexpected token else

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.

And all of the code is below:

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

#2

@alexmcburnie
You have to be careful in the usage of the semi-colon-;

For the Javascript-interpreter a semi-colon-; is an End-of-Statement indicator....

Thus if you write the code like

if(event.which === 111);

the IF statement is ENDED....


#3

That's it, thanks! Not too sure how I didn't spot it.


#4

This topic was automatically closed after 28 hours. New replies are no longer allowed.