Make Sure You Have Defined All Variables


#1

I can't seem to find the problem with my code! Can someone help me fix it please? I keep getting a message saying I have to define variables:

var main = function() {
    $('.btn').click(function() {
        var post = $('.status-box').val();
        $('<li>').text(post).prependTo('.posts');
        $('.status-box').val('');
    });
    
    $('.status-box').keyup(function() {
        var postLength = $(this).val().length;
        var charactersLength = 140 - postLength;
        $('.counter').text(charactersLeft);
    });   
    
};



$(document).ready(main);

#2

Hi Tor,

Please post a link to the exercise you're on so we can help you.
Thanks!


#3

Hi @zystvan,
Thanks for getting back to me, I should has specified, sorry! The lesson I'm in is making an interactive website: status update lesson 6: reset the counter. Let me know if you need anymore info!

Tor


#4

Thanks for the exercise number - I should have looked closer at your code, I actually didn't need it though. But thanks anyway, it's good to include the exercise just in case :smile:

var charactersLength = 140 - postLength;

should be:

var charactersLeft = 140 - postLength;
           // ↑ `Left` instead of `Length`