Need Help on "The O Shortcut"


#1

I am having the same problem...

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

$(document).ready(main);

I have checked over 10 times for syntax errors, for the life of me I can't find any. I even tried copying and pasting the hint code and it still won't do it. I am starting to suspect that this excercise is bugged.


The o shortcut
#2

$("article").click(function() { See anything wrong? Hint Double quotes, instead of single


#3

I thought that it didn't matter if it was single or double quotes? O_o


#4

I got it working. For some reason, it was letting me pass before even though the code was wrong syntax wise.


#5

Actually I did notice the single quotes and double quotes difference and even tried using single quotes on this exercise. It still doesn't do it, it won't let me through. I noticed that despite some syntax errors I had in previous excersises the compiler marked me as correct. I still believe that there is something off in that section of the course that needs to be revised.

My code is looking like this so far...

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

$(document).ready(main);

#6

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

$(document).ready(main);

On line 5 your code should be $('.article').removeClass('current') removing the . before current. because the computer knows you're using classes, there is no need for that period.

$(this).hide('.description') should be $('.description').hide();

Hope this helps.


#7

You can either use double quotes or single quotes, not a mix of both, except for situations like $("<p>").text("i'm here to help"); In this case we can't use double quotes for the I'm because that would end the string, so we use the other quote (in this case single ' quotes)


#8

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

turns out that keypress function should be independent of that click function, not inside it. Hopes it helps!