Code not Passing


#1

app.js

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

Everything is right, but the error message says the O button is NOT working.


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

$(document).ready(main);

#2

Hi the $(document).keypress(function(event) {..}); shouldn't be inside the $('.article').click(function(){ }); but inside the man function so your code should be look like that

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

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

#3

Can I ask why? What difference does it make?


#4

Hi the difference will be that they are two differente function that do two differente thing one will show you the hide information by just click on it

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

and another that will show you the hide information by pressing a key in this lesson o

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

and since they do two differente thing in Real-life(if you do your own code) it will be better to have two function instaed of just one. by neaster one in the other


#5

Oooh, I see! Thank You!

Could you also tell me what differences these two pieces of code make? --->

var main = function() {};

$(document).ready(main);

// and this one

$(document).ready(function () {});


#6

it's the same here you have

$(document).ready(main);

since main is a function

var main = function() {
   #here the code
}

its the same as

$(document).ready( function {
   #here put the code
});

the only diference is the structure the first one

var main = function() {
   #here your ocde
}
$(document).ready(main);

and the second on

$(document).ready(function () {
   #here put your code
});

the second one is easy to read on how it work document ready run the function and the first one call the function in the $(document).ready(namFunction)