Trouble with The N Shortcut 2


#1

Hello below is the code I am using, and keep getting a message that isn't moving to the next article. Can someone please help? Thanks

$(this).addClass('current');
$(this).children('.description').show();
});
$(document).keypress(function(event) {
if(event.which===111) {
else if(event.which===110) {
    var currentArticle = $('.current');
      var nextArticle = currentArticle.next();
      
      currentArticle.removeClass('current');
      nextArticle.addClass('current');
    }
  });
}
$(document).ready(main);

#2

Hi Jj,

I see two problems in your code:

  1. You're missing approximately the first 1/4 of the code (var main...)
  2. You've nested your else if statement inside your if statement

#3

Sorry about that, here is the full code I am using. I'm still getting the same 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) {
});
else if(event.which===110) {
var currentArticle = $('.current');
var nextArticle = currentArticle.next();

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

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


#4

@jj.epstein Better, but here:

You need to close only the if statement, nothing else, so remove the closing parenthesis ()) there. Then, you need to put the code the lesson wants inside the if statement, it shouldn't be empty.


#5

Sorry it's still not working.

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

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

$('.current').children('.description').toggle();
}
});
}
$(document).ready(main);


#6

@jj.epstein

No worries :slightly_smiling:

You're back to your original code, though. Go back to your code in post #3, and do exactly what I say in post #4.

The if statement should look like:

if (event.which == 111) {
  // ...
}

except that you'll replace the // ... with actual code. The exercises should tell you what to replace the comment with :slightly_smiling:


#7

Sorry it's still not working. What do you mean by actual code? I thought I did.

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

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

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


#8

@jj.epstein Look here:

Without giving away the exact code, since that's sometimes frowned on, this is what that part needs to look like:

$(document).keypress(function(event) {
  if (event.which == 111) {
    // CODE HERE (the instructions will tell you what to put here)
  } // ← you're missing this closing curly brace
  else if (event.which == 110) {
    // CODE HERE - put the code you already
    // have in your `else if` statement here
  }
});

Does that help?
I'm sorry this is so confusing for you :frowning:


#9

Thank you that worked.