The 'O' Shortcut, Number 7


#1

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

The code does not open the description when the ‘o’ key is pressed. I keep getting the error 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.”



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

};
$(document).ready(main);



#2

HI this part

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

should be outiside the…

$('.article').click(function() {

})


#3

Do you mean this? I tried that and it didn’t work.
var main = function() {
('.article').click(function() { (’.description’).hide();
(this).addClass('current'); (this).children(’.description’).show();
('.article').removeClass('current'); (’.description’).hide();
});
(document).keypress(function(event) { if(event.which === 111) { (’.current’).children(’.description’).toggle();
(this).children('.description').show(); } }); (this).children(’.description’).show();
});

};
$(document).ready(main);


#4

should be like that

var main = function() {
    $('.article').click(function() {
        $('.description').hide();
        $(this).addClass('current');
        $(this).children('.description').show();
        $('.article').removeClass('current');
        $('.description').hide();

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

#5

I understand it now, thank you! :smiley:


#6

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