Disable Button 1 : Make sure you have defined all the variables!


#1

var main=function(){
    $('.btn').click(function(){
        var post;
        post=$('.status-box').val();
        $('<li>').text(post).prependTo('.posts');
        $('.status-box').val('');
        $('.counter').text("140");
         
        
        
    });
    $('.status-box').keyup(function(){
       
        var postLength = $(this).val().length;
        var charactersLeft = 140-postLength;
        $('.counter').text(charactersLeft);
        if(charactersLeft<0)
        {
            $('.btn').addClass('disabled');
            
        }
        
        else if(charctersLeft== 140)
        {
            $('.btn').addClass('disabled');
        }
        else
        {
            $('.btn').removeClass('disabled');
        }
        
    });
   $('.btn').addClass('disabled');
    
};

$(document).ready(main);

I get the error Make sure you have defined all the variables!.Please help me locate my mistake.
Thank you


#2

Hi Rahul,

Your code isn't currently fully visible. Please see Using backticks to format your code, then edit your post to fix it, and leave a reply to this so I'll get a notification :slightly_smiling:
Thanks!


#3

Sorry about that , edited it now


#4

charactersLeft is misspelled in your else if condition.


#5

omg ,thank u so much :stuck_out_tongue: