Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript jQuery Basics (2014) Creating a Spoiler Revealer Perform: Part 2

Pavel Makeev
Pavel Makeev
6,207 Points

jQuery Basics. Please, Help

//1.Hide spoiler $(".spoiler span").hide(); //2.Add a button $(".spoiler").append("<button>Reveal the spoiler</button>"); //3.When the button s pressed if(

$("button").click(function(){ //3.1 Reveal spoiler $(".spoiler span").show(); //3.2 remove button

   });

Concole returns: Uncaught SyntaxError: Unexpected token ;

I can't understand, what's wrong with the code.

1 Answer

Kirkland Harrell
Kirkland Harrell
4,444 Points

So this is your code...

//1.Hide spoiler 
$(".spoiler span").hide(); 
//2.Add a button 
$(".spoiler").append("<button>Reveal the spoiler</button>"); 
//3.When the button s pressed 
if($("button").click(function(){ 
  //3.1 Reveal spoiler 
  $(".spoiler span").show(); 
  //3.2 remove button
});

For the section //3 'When the button is pressed'...you have the beginning of an if statement which isn't necessary, it should simply be:

$("button").click(function(){
Pavel Makeev
Pavel Makeev
6,207 Points

How stupid of me :( Thanks a lot!