7. The O Shortcut


#1

I've clicked "reset code" and literally copied and pasted the code from the hint and I'm still getting this error:

"Oops, try again.
It looks like the o key isn't opening a description. Remember to
toggle the current article's description inside the event handler. Look
back at the instructions for the code."

while underneath the page preview it says:

"SyntaxError: missing ) after argument list"

var main = function() {
    $('article').click(function() {
        $('article').removeClass('current');
        $('description').hide();
        
        $(document).keypress(function(event){
            if(event.which === 111) {
                $('.current').children('.description').toggle();
            }
        });
        
    $(this).addClass('current');
    $(this).children('description').show();
    }
}



$(document).ready(main);

#2

Move this out of the click event handler so it is independent..

The click handler is missing a closing parens. );


#3

I had trouble with this exercise too. Even following this, I still couldn't advance. Here is the link:

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

Can you explain what we are supposed to do? It was very confusing by your instructions. You said move out


#4

var main = function() {
    $('article').click(function() {

    });
    $(document).keypress(function(event){
        if (event.which === 111) {
            $('.current').children('.description').toggle();
        }
    });
};

#5

The suggested fix is not working. Still getting this error: Uncaught SyntaxError: Unexpected token }


#6

This fixed the syntax errors but the functionality does not work. At least you can move on to the next exercise - 8

var main = function() {
$('article').click(function() {

});
$(document).keypress(function(event){
    if (event.which === 111) {
        $('.current').children('.description').toggle();
    }
});

 
 $('.article').removeClass('current');
$('.description').hide('current');
$(this).addClass('current');
$(this).children('.description').show();

}
$(document).ready(main);


#7

All of the above code needs to be inside the click handler.


#8

thanks for all your replies. i managed to fix it finally.
here is my updated code:

var main = function() {
    $('article').click(function() {
        $('.article').removeClass('current');
        $('.description').hide('current');
        $(this).addClass('current');
        $(this).children('.description').show();
            });
        
    $(document).keypress(function(event){
        if(event.which === 111) {
            $('.current').children('.description').toggle();
                }
            });
    
    $(this).addClass('current');
    $(this).children('description').show();
    }

$(document).ready(main);

i moved the keypress function out of the click function.
i added all of mtf's code to my click handler.
and i found out that i had an extra "}" bracket at the end, so i deleted it.


#9

Those last two lines can be removed.


#10

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