Step 7: Remember to add the line $('.btn').addClass('disabled'); outside your keyup event handler


#1

I can't figure out what went wrong here. Probably a typo, but I can't seem to find it. Help would be greatly appreciated.

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);

#2

Hey @digitalwhiz08404,

I had the same issue.

Just copy $('.btn').addClass('disabled'); under $('.counter').text(140); (in the .click()-function) then your code should work properly.
The exercise is written a bit inaccurate ...

Hope that I could help you :slight_smile:


#3

Following your instructions hasn't resolved the problem.
This is what my code looks like now:

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

  • ').text(post).prependTo('.posts');
    $('.status-box').val('');
    $('.counter').text(140);
    $('.btn').addClass('disabled');
    });
    $('.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');
        }
    });

    };
    $(document).ready(main);


  • Lesson 5 error message
    #4

    EDIT: I see your fault now. It's on the 6th Line: .text('140'); instead of .text(140); ... so you gotta put the 140 in quotation marks... :slight_smile:


    My code looks like this ...

    var main = function() {
      $('.btn').click(function() {
        var post = $('.status-box').val();
        $('<li>').text(post).prependTo('.posts');
        $('.status-box').val('');
        $('.counter').text('140');
        $('.btn').addClass('disabled'); 
      });
      
      $('.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);

    ... and works pretty well. Try it :stuck_out_tongue:


    #5

    It worked, thank you very much!


    #6

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