Count Characters Left


#1


https://www.codecademy.com/en/courses/web-beginner-en-hk5qh/0/5?content_from=make-an-interactive-website%3Ajquery-dom-manipulation

The keyup() event decrease the length of characters in the status box. How is the character counter increased after pressing 'Backspace' or deleting a character?


$('.status-box').keyup(function(){
        
        var postLength = $(this).val().length;
        var charactersLeft = 140-postLength;
        $('.counter').text(charactersLeft);
        });


#2

Every event results in a new character count of the text in the form control. Backspace or delete will reduce the count since they are not printing characters.


#3

Yes but where is the code for reducing the count?


#4

postLength gets redeclared and set on every handled event. charactersLeft, likewise. There is no running variable to increase or decrease.