(13) The code doesn't work but it is accepted


#1



There are no error messages – the code is actually accepted – but it doesn't do what I think it is supposed to do. I used the remove() method on the $(this) object directly as the third parameter of the on() method that is acting on the $(document) object rather than including it in a function(), as suggested by the lesson. Is this appropriate?

$(document).ready(function() {
    $('#button').click(function() {
        var toAdd = $('input[name=checkListItem]').val();
        $('.list').append("<div class='item'>" + toAdd + "</div>");
        });
    $(document).on('click', '.item', $(this).remove());
    });


#2

The above should be wrapped in a function body.

..., function () {
    $(this).remove();
});

You tell us. Did the item get removed when you clicked it? If it did, then one supposes the code is okay. Is it appropriate to not follow instructions? That I would say is questionable.


#3

If you read my post carefully, you will notice that I have acknowledged that.

The item did not get removed when I clicked it. Then again, the program accepted the code even though it didn't work. This means that the program is malfunctioning, so it is not a reliable indicator of the correctness of the syntax I used. To rephrase the question:

Is it appropriate to pass code that is not wrapped by function() as the third parameter of an on() method?


#4

The lesson checker is not exhaustive and lets lots of incorrect or incomplete code pass the lesson. It's not a malfunction as much as a possible oversight on the part of the course author. These old courses were written by volunteers a long time ago, and have survived the test of time, despite their apparent flaws.

We are to take it upon ourselves to varify that we are on the right track. What do we expect our code to do? Does it do what is expected? If not, then why?


#5

The lesson checker should not let incorrect or incomplete code pass the
lessons. Codecademy is one of the most popular sites for learning code and
as such its staff should be dedicated to providing qualitative and accurate
lessons. This becomes even more important when we consider the nature of
programming i.e. it is based on exact science.

In this case, I simply wanted to learn the answer to the question above.
Codecademy did not provide this. My intuition tells me that the syntax is
correct, but I still do not know for sure and that's why I have posted it
here. I hope someone will answer.


#6

Your intuition is wrong, as we've already seen. Your code did not remove the clicked item because it was not written as a callback (a function expression).

Lecturing me on what CC should or should not do is of no use. We are not employees of Codecademy and this is only the Q&A forum. We are not the ones you should be lecturing. Write to Codecademny.


#7

Where have we seen it? In the malfunctioning program? Maybe that was just an oversight?

Previously, you tried to evaluate my code using the program's response. I argued that that's unreliable. It follows the lecture.

I will forward the lecture to Codecademy. I thought you were part of the team.

Thank you for the answer.


#9

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