"The O shortcut" not working propperly


#1



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


The code works in the web viewer but the course wont let me countinue! I get this message:
"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."

Now, I've seen throught a lot of other peoples answer and landed on my original code, seen below. When I try to open the description using the "o" key, it works just fine.


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).ready(main);


#2

HI your code should have that structure

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

    $(document).keypress(function(event) {
        ....
    });
};

$(document).ready(main);

#3

Thank you, that change worked


#4

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