The o Shortcut


#1

Hi, I keep getting an "Uncaught SyntaxError: missing ) after argument list", but I can't find it anywhere. I've compared my code to loads of other people's on here, but I can't seem to find my error.
Here's my code:

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

var main = function() {
$('.article').click(function() {
...
}
});

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

$(document).ready(main);

Thanks in advance!:grin:


#2

Hi Alex,

You can't have a main function inside a main function. Remove that part. Then, move the closing curly brace (}) on line 7 down to the next to last line.

If you're still having trouble, please post your complete, untruncated code, properly formatted:

https://discuss.codecademy.com/t/how-do-i-format-code-in-my-posts/28351/1?u=zystvan


#4

Oh wow, I can't believe I didn't notice that--- I removed the second main function, but I don't understand where you're telling me to put the second } - anywhere I put it, I just get "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." and "Uncaught SyntaxError: missing ) after argument list" shot back at me.
Here's the mess that I have now.

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


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

$(document).ready(main);

I probably junked it up even more than before, so apologies in advance. Thanks.


#5

@tree_octopus That's much better, and great job formatting your code properly :+1: :slightly_smiling:

Your code works properly (except for that you're closing $('.article').click(...) and main in the wrong order), but the SCT (Submission Correctness Test; code checker) is expecting everything except for your very last line to be inside the main function. So if you move your closing curly brace (}) on line 7 down to line 16, your code should pass :slightly_smiling:


#6

That fixed it! Thank you so much :slightly_smiling: