"It looks like the o key isn't opening a description" error on exercise 7


#1

I'm having the same issue. I have the event handler able to toggle the class, but I'm still not allowed to progress. I keep getting the "oops" message.

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);

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.


7. The o shortcut Interactive Website: News Reader
#2

@klinger1 add/remove/toggleClass() take a class name, minus the dot (.) you normally use, as the input. So, addClass('.current'); should be addClass('current'); :)


#3

I removed the periods (.), but I'm still not allowed to progress, even though when I press the 'o' key, the article's description is toggled on and off. I have the ability to show and hide the description with the 'o' key, but it still says it's wrong. I even have the code arranged like the hint provides.

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

2 posts were split to a new topic: Exercise 7, "It looks like the o key isn't opening a description" error


#5

@klinger1 The rough skeleton of your code should look like this:

var main = function() {
  $('.article').click(function() {
    // do stuff
  }); // ← this needs to be closed before the next function
  $(document).keypress(function(event) {
    // do stuff
  });
}

$(document).ready(main);