"O" kerpress shortcut isn't working


#1



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


The "O" shortcut to open the selected article isn't working. I'm not sure what is wrong with the code. Could any of you help me identify the problem.


var main= function() {
  $('.article').click(function () {
      $('.article').removeClass(); 
      $('.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);

And

if (condition) {

}

#3

Your code

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

}





$(document).ready(main);

A few things I noticed.
1. on line 3, your code should be $('.article').removeClass('current'); so that the computer knows which class to remove!
2. On the line before $(document).keypress(function(event) { you should close article.click function on line two by adding });
3. After $('.current').children('.description').toggle(); you should close the if(event.which === 111) { line with a }
before your });
4. On your } before $(document).ready(main); you should add a semi-colon.

 Hope this helps!!!

#4

Thanks so much. It worked perfectly. I'll start focusing more on closing each line, and function.


#5

I could help to see where this error

and I am giving me this when I give check

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 () {
$('.article').removeClass('current');
$('.description').hide();
$(this).addClass('.current');
$(this).children('.description').show();
$(document).keypress(function(event) {
});

          $('.current').children('.description').toggle();

if(event.which === 111) {
}
});

}

$(document).ready(main);


#7

Why is there no code in here??


#8

A post was split to a new topic: Uncaught Syntax Error: Unexpected token if