Can't get past "7. Disable the button 1" and I've looked at all the other


#1



https://www.codecademy.com/en/courses/web-beginner-en-hk5qh/0/7?content_from=make-an-interactive-website%3Ajquery-dom-manipulation


I know this topic has appeared on the forum a lot and I'm sorry to bring it up again, but I really am stuck. I have looked at all the other threads on this and can see where others have made errors but I really can't see where I've gone wrong with my code. It worked fine for the previous exercise and all I've added is the $('.btn').addClass('disabled'); to disable the button.

The error message I get is:

Oops, try again.
Remember to add the line $('.btn').addClass('disabled'); outside your keyup event handler

But the line is outside the keyup handler. Below the preview box on the right of the screen I also get "SyntaxError: missing ; before statement" - I can't see where I'm missing a ";" but perhaps this is where I'm going wrong.

I have checked my code against the Hint box and it looks like an exact match. I'm really stuck and want to know where I've gone wrong so any help would be much 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

Hi in the else satetement

else {
    $('.btn')removeClass('disabled');
}

i'ts missing the dot between $('.btn') and removeClass('disabled')


#3

@elitestarquake,
In such situation of having to look for an error
you can pin-point the problem area
by using =Multi-line-commenting=
like

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

the =error= should have disappeared.....

AND
using

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

still no error,
thus what is wrong ????


#4

That did it! Many thanks.

Interestingly, when I corrected this, tested it worked that clicked "Save and submit" and moved on to the next page, the "." was missing from the same position in the same "else" statement. This could explain why it worked for me on step 6 but not 7 - however I cannot explain why the "." was going missing between the steps.

Anyway, many thanks again.


#5

This helped me and is a great technique for debugging. Many thanks for helping a newbie!


#6

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