How to update the counter


#1

What am I doing wrong?

var main = function() {
$('.btn').click(function() {
var post = $('.status-box').val()
$('

  • ').text(post).prependTo('.posts');
    $('.status-box').val('');
    });
    };
    $('.status-box').keyup()function()
    var postLength =$(this).val().length;
    var charactersLeft = -140 postLength;
    $('.counter=140').text() charactersLeft;
    };
    $(document).ready(main)

  • #2

    Hi Chris,

    I'm guessing you're on exercise six, Count characters left?

    You've got a bunch of problems in your code. From top to bottom:

    • Line 7 should be removed
    • Line 8 should have $('.status-box').keyup(function() {
    • Line 10 needs to be 140 - postLength;, not -140 postLength;
    • Line 11 should look like this: $('.counter').text(charactersLeft);
    • And on line 12, you need to add }); before the };.

    If you're still having problems, please post your updated code.
    I hope this helps :)


    #3

    Hello Zyztvan my code looks exactly like what you posted but i still get error to update '.counter.
    See my code below:

    var main = function(){
    $('.btn').click(function() {
    var post = $('.status-box').val();
    $('

  • ').text(post).propendTo('.posts');
    $('.status-box').val('');
    });
    $('.status-update').keyup(function(){
    
    var postLength = $(this).val().length;
    var characterLeft = 140 - postLength;
    $('.counter').text(characterLeft);
    
    });

    };


  • #4

    @lawreneagles Please create a new topic, then post the link to it here, & I'll help you over there. And if you could include the error message you're getting, as well as your code, it'd be great :)


    #5

    Thank you for your Help


    #6

    Have the same question. How to reset the counter to 140 after "Post" was clicked


    #7

    @kybinsky Please create a new topic with your code, a link to the exercise you're on, and your question - someone will help you over there :)
    Thanks!