9. n shortcut 2


#1

I'm getting the error message: "Oops, try again. It looks like the n key isn't moving to the next article. Remember to remove the 'current' class from currentArticle and place it on nextArticle."

What am I not understanding?

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

          else if(event.which === 110) {
  var currentArticle = $('.current');
  var nextArticle = currentArticle.next();

  currentArticle.removeClass('current');
  nextArticle.addClass('current');
}
    
});

Thanks in advance.


#2

Hi Ella,

  1. Line 8, you've got an unclosed single quote (')
  2. Line 11, you can't have a semi-colon (;)
  3. You need to call main outside of itself
  4. Your else if statement needs to come immediately after an if statement

If you're still having trouble, please post a link to the exercise you're on and your updated code :slight_smile:


#3

Hi,
Thanks for getting back to me. I made the change but I'm still getting the error message: " Remember to remove the 'current' class from currentArticle and place it on nextArticle." What does this mean?

Here is a link to the exercise The n shortcut 2: https://www.codecademy.com/courses/web-beginner-en-4hxyb/0/9?content_from=make-an-interactive-website%3Ajquery-events

And a copy of my code. Please note there's also a syntax error I'm not spotting:

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();
}
});
else if(event.which === 110) {
var currentArticle = $('.current');
var nextArticle = currentArticle.next();

currentArticle.removeClass('current');
nextArticle.addClass('current');
}

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

Thanks again


#4

Line 7..we don't add a class using the dot (.) remove it.
Line 16 you have closed the keypress function and then starting the else if statement. else if should be next to if statement and close the keypress function at the end of else if

hope that helps


#5

Hey, I made the changes but still not working. Here's my updated 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();

      else if(event.which === 110) {

var currentArticle = $('.current');
var nextArticle = currentArticle.next();
});

currentArticle.removeClass('current');
nextArticle.addClass('current');
}

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


#6

Nevermind - it appears I didn't close it with the necessary } bracket. Thanks for the help!


#7

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