R 7. The o shortcut


#1

I need some help, I can't figure out why my code is not running correctly.
I have even copied and pasted the lesson hint/example but it still does not display

Do any one have suggestions? Here is the code:

var main=function(){

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

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

            if(even.which===111){
             $('.current').children('.description').toggle();

              }
            });        



        });       
      });     


    $(document).ready(main);

#2

Hi,
I struggled here a little while too.
I think the problem was that the entire function of $(document).keypress(...) should not be placed within the $('.article').click(...).

Instead, the keypress part should be placed under the main function, and is parallel with the click function.
Hope it helps!

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

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

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

#3

Thank for the tip! but unfortunately I am still getting the same 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.

But here is my 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();
                
              }
      });     
    
  
    $(document).ready(main);

#4

Hi
The problem is that you have two of this "});" in the middle of the code ... and you need one more this "}" at the end... your code works 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();
            
          }
  });

}


#5

@kuro9206

You are my hero! Thank you!


#6

This isn't working for me.


#7

ive tried everybodys code but NOTHING WORKS
:rage:[
I


#8

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