Disable the Button 1 (again)


#1

Hi
I'm stuck on this exercise, can't see what is wrong with my code ?

I get 2 alerts
"SyntaxError: expected expression, got keyword 'else'"
and
"Oops, try again.
Remember to add the line $('.btn').addClass('disabled'); outside your keyup event handler"

Please help me !

var main = function (){
    $('.btn').click( function (){
        var 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 (charactersLeft===140) {
            $('.btn').addClass('disabled');}
        else { 
            $('.btn').removeClass('disabled');
            }
        
        })  ;
     $('btn').addClass('disabled');   
    }

$(document).ready(main);

Thank you for your help !


#2

Got it !

 $('btn').addClass('disabled');   become       **$('.btn').addClass('disabled');**

#5

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