7. The 'o' shortcut


#1



https://discuss.codecademy.com/c/make-an-interactive-website/web-beginner-en-4hxyb

<My code actually behaves ok, I am just getting the following error message:

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."

Testing it out, the 'o' shortcut toggles the description of the selected article on and off as I believe it should. I'm just curious what the SCT might be looking for?

Thanks in advance for any/all help._>


function main() {};

$(document).ready(main);

 $('.article').click(function() {    
//*function opening ( closed line 16, open brace closed line 16*\\
    $('.article').removeClass('current');
    $('.description').hide();

    $(this).addClass('current');
    $(this).children('.description').show();
    
    $(document).keypress(function(event) {  
//*function opening ( closed line 18, function brace closed line 18*\\
    if(event.which === 111) {
        $('.current').children('.description').toggle();
    }
 });//*closing brackets for keypress function*\\
 
  });//*closing brackets for click function*\\
  
  //*'o' shortcut does function in window.


#2

Hi you code should have this structure

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

    $(document).keypress(function(event) {  
        ....
   }); #close document keypress function
}#close the main functon

#Then at the end put this line
$(document).ready(main);

#3

Thanks a lot, @wizmarco. The two mistakes that you pointed out satisfied the problem. May I ask whether what I needed to fix was for the benefit of the SCT or was my code, in fact, in error?

As I said, it was still functional, however maybe I was setting myself up for bugs down the line? I'd just like to know what's up.


#4

what I needed to fix was for the benefit of the SCT or was my code, in fact, in error?
it was an error..
because like you can see

$(document).ready(main);

you put the main (which is the main function) inside the .ready() so if you doesn't have anything inside it

function main() {};

it normaly should give you an error..


#5

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