I can't find any solution for this


#1



https://www.codecademy.com/skills/make-an-interactive-website/topics/jquery-events/jquery-click-try


The button doesn't change the color.
And I tried any kind of solutions by replacing btn with btn-like and btn-like with 'this or
by replacing just btn-like with 'this or
by replacing toggleClass with toggle...
But, anyway.. I just can't figure out the solution.

var main = function() {
  $(".btn").click(function() {
		$("btn-like").toggleClass('active');
  });
};

$(document).ready(main);


#2

The instructions say:

Fill in the event handler below to apply the class "btn-like" to the $(".btn") element. Use .toggleClass() to apply the class. Use this to operate on the already-selected HTML element.

The event handler is the on click event, which is being hooked to btn. On click, btn should have the "btn-like" class toggled on or off. The class "active" is not mentioned in the exercise...

With the above said, the code should be:

$(this).toggleClass("btn-like"); //where "this" is the element clicked, btn

I hope that helps.


#3

Yes, the instructions say apply the class "btn-like" to the $(".btn") element, but where it says how to apply it? It was so frustrating and I could not find any clue how to do that! I have to build a new account to log in this Codecademy community and search for the answer. Why not just tell us at the very beginning that you have to learn Javascript first to start this course?


#4

And BTW, these are two pieces of codes provided by the instruction before this question:

var main = function() {
$(".like-button").click(function() {
$(this).toggleClass("active");
});
};

$('.social li').click(function() {
$(this).toggleClass('active');
});

Of course we want to find some where to put the 'active', otherwise what is the point to show these two blocks of codes? The design of this course is the worst I have ever seen in codecademy.


#5

The course doesn't really require you to know jQuery. If anything, it is a very basic introduction to jQuery/JavaScript, and you will probably not want to go through the course if you already know the language and library (I started the course and found it to be a bit of a snooze fest).

A lot of it is very copy-paste like.

var main = function() {
      $(".like-button").click(function() {
            $(this).toggleClass("active");
      });
};

The class "active" above is the same as the class "btn-like" on the OP's post. Likewise, ".btn" is the same as the previous example's ".like-button".

Codecademy provides you an example, then follows up with an exercise of very similar code (but different names), but both pieces of code are very similar. It is simply testing if you understood the code it showed on the past screen.

Maybe they need to be more verbose within the course to get the concept across, and rely less on "I-show-you-mine-you-show-me-yours" examples?


#6

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