N Shortcut Error "Uncaught SyntaxError: Unexpected token )"


#1

Please help. I can't seem to find what I have done 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();
        }
        
        else if(event.which === 110) {
    });
}

$(document).ready(main);

#2

Hi Xchowx,

You need to close your else if statement with a closing curly brace (}) before the last }); line.


#3

That didn't make a difference.


#4

@xchowx Please post your updated code.


#5

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

}

$(document).ready(main);


#6

@xchowx Maybe I should've been more clear, sorry. You add the closing curly brace after the opening curly brace ({). The opening one doesn't get replaced by the closing curly brace :slightly_smiling:


#7

Sorry can you please copy paste my code the corrected way? I am still very confused.


#8

I'm sorry that I'm not the same person, but the issue zystvan seems to be pointing out is this:

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

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

});

Specifically:

else if(event.which === 110) }
});

The correct code for this would look like:

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

Notice how the

};

on the last line corresponds to the original function for the keypress event. You might think the

});
}

closes the else if statement, but the parentheses next to the curly bracket on the first line closes the function.

In conclusion:
change:

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

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

}

to:

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

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

});

and fill in

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

the curly brackets with the correct code that follows the directions. :slightly_smiling: Good luck!


#9

Thanks heaps. This fixed it.