I'd appreciate any kind of help: "Uncaught SyntaxError: Unexpected End of Input"


#1

I have a similar issue. I'd appreciate any kind of help. Thx!

Excercise: https://www.codecademy.com/en/courses/web-beginner-en-4hxyb/0/7?content_from=make-an-interactive-website%3Ajquery-events#

Here's 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);


"Uncaught SyntaxError: Unexpected end of input"


Make an interactive website dilema
#2

@rautavuori

You need to close your main function with a closing curly brace (}) just before you call it.


#3

Thanks! But I still don't get it. :smiley:

"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 hints, please?


#4

@rautavuori Hm, could you post your updated code?


#5

Hi, zystvan,

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();
  }
});
}
$(document).ready(main);

Thx in advance!


#6

@rautavuori

Wrong:

$('.document')

Right:

$(document)

$(document) selects the entire HTML page, and is a variable predefined by jQuery. $('.document) selects any HTML element with the class="document" attribute.


#7

That helped. Thank you very much, zystvan!

The editor says that "way to go" (see picture attached below),

But actually my code isn't working properly. I mean that pressing the o key does not toggle the current article's description.

Any ideas? Or is it just a bug on Codeacademy.com?


#8

@rautavuori You'll probably need to click on an article first, then press the O key.


#9

"ou'll probably need to click on an article first, then press the O key"

Hi, zystvan,

actually I've tried that. Did not work.
So maybe it's just a bug on Codeacademy.com.

Thx anyway!


#10

Ah. No, I was wrong, I missed something else in your code. addClass doesn't take a dot (.) before the class name, so line 5 needs to look like this instead:

$(this).addClass("current");

This post should explain why you need to do it that way:

:slight_smile:


#11

Great! Thank you so much! :smiley: :+1:


#12

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