7/9 Disable the button 1 problem


#1

I've endlessly been staring at my code and still don't know what is wrong. I receive the message: "Oops, try again. Remember to remove the class "disabled" from the Post button after the user starts typing." Anybody could help me with this? Here is my code:

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

Hi Galazka23,

In JavaScript, one equal sign (=) sets a variable equal to a value. Two or three equal signs compare the variable's value to your comparison value.

So this line:

Actually needs to look like this:

                       // ↓ third `=` can go here if you want
else if (charactersLeft == 140) {

#3

Many thnaks for the explanation! It works!


#4

2 posts were split to a new topic: What is the correct syntax for 7/9?


#5

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