Stuck with the n short cut 2


#1



please i'm stuck here
can any 1 tell me where is the wrong part?
i wrote this code many times and doesn't work.

https://www.codecademy.com/courses/web-beginner-en-4hxyb/0/9?content_from=make-an-interactive-website%3Ajquery-events#


the erroe says : Uncaught SyntaxError: missing ) after argument list.
and


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

Hi here your 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();
        }
        else if(event.which===110){
            var currentArticle = $('.current');
            var nextArticle = currentArticle.next();
            currentArticle.removeClass('current');
            nextArticle.addClass('current');
        }
               };
           );
};
$(document).ready(main);

can you see what's wrong?

Hint

var main = function() {
    $('.article').click(function() {
        ........
    });
    $(document).keypress(function(event) {
        if (event.which === 111) {
            .....
        }
        else if(event.which===110) {
            .....
        }
           }<== remove this one 
    }  <= #this one should be }); because it close the $(document).keypress..
}


#3



thank you for your respond
now after editing my codes here is the error


Uncaught SyntaxError: Unexpected token else


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

Continuing the discussion from Stuck with the n short cut 2:


#4

remove the ; after the if statement

if(event.which === 111) {
    $('.current').children('.description').toggle();
}; <== this one

#5

thank u very much i guess i'm still confused
i really hate java and js
:joy:


#6

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