jQuery- The o shortcut


#1

I cannot figure out what's messed up with my code! It keeps telling me that my shortcut is messed up, but I cannot figure out the problem that keeps it from opening. This is the message I keep getting:

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.

Any help would be most appreciated!

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


#2

Is the highlighted part of the code a typo or part of your code?

$('article').removeClass('current');
  ^^

It might be the cause. To fix it, just add a period between the two characters.


#3

I tried to add the period there, but it's continuing to tell me the same thing... thanks though!


#4

Hi Kathrynrose,

@mathwizzy101 is correct, you need a . in front of article, since it's a class name. Also, $(this) and $(document) do not use quotes, that's likely why you're having trouble.


#5

I tried all of your suggestions, but it is still coming up as wrong!


#6

Could you post your modified code please?


#7

Hello,

I'm having the same problem. Here is my code:


var main = function() {
$('.article').click(function() {
$('.description').hide();
$('.article').removeClass('current');

    $(this).addClass('current');
    $(this).children.('.description').show();
});

$(document).keypress(function(event){
    if(event.which === 111){
        $('.current').children('.description').toggle();
    }
}

};

$(document).ready(main);

Also, throughout this exercise the code hasn't been executing properly in the little window at the top right, even though I am told I have completed the exercise correctly. With the code I've written above I also get the message:

Uncaught SyntaxError: Unexpected token (

which has followed me since the beginning of the News Reader lesson.

cheers!


#8

@arcblaster65363 I think the problem is on line 6:

$(this).children.('.description').show();

It should look like this:

$(this).children('.description').show();

#9

Hey. I had the same issues, but figured it out. Apparently, my code wasn't working since the .keypress function was still within the .click one. Cut/paste it below the .click closing brackets and that should do the trick.

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


#10

Thanx a lot for the the tip it worked! I was stuck at this stage for a very long time


#11

Hi,

I am having problems with the Interactive Website News Reader.

Please help.


#12

@keznjoebigpond_com Please create a new topic and copy/paste your code into it - screenshots are hard to work with - and include a link to the exercise you're on and the error message you're getting.
Trying to hijack someone else's topic doesn't do anyone a kindness.
Thanks!


#13

Sorry it wasn't my intent to hijack someone else's topic, I am still learning how to navigate my way around the site etc, and I dont' find the Q&A section very clear.


#14

I've looked at everyone's suggestions here, but still get the following error:

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.

Here is my code, it looks exactly like everyone's and I'm using google chrome browser to do this...not sure what exactly is wrong:

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


#15

Omg just took one second to look at it again, forgot the quotes around 'article' in the top of the code... >_<


#16

I'm still not able to figure out where I made my error. Can anyone with fresh eyes help me?

var main = function()
$(document).keypress(function(event) {
if(event.which === 111) {
$('.current').children('.description').toggle();

});
$('.article').click(function)(){
$('article').removeClass()
$('.description').hide()
$(this).addClass('current');
$(this).children('description').show();
});
};
$(document).ready(main);

Error message I get is:

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.

Thanks,


#17

@julienk403 Please create a new topic, and we'll help you over there :)


#18

Worked! Thanks for posting your tip, had the same problem.


#19

Thank you sooo much! I was going through all the forums on here and no one was actually doing it right. I really appreciate it :grinning: .


#20

this is the 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) {
$('.description').hide();

  $('.current').children('.description').show();
}

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

});
}

$(document).ready(main);

It Helps u thro all the exsersizes of that level