"Count Characters Left", Why Doesn't this Work?


#1



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


Why this doesn't work ?


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


#2

What exactly you are trying to accomplish with this code?


#3

$('.status-box').val() = $('.status-box').val('');

It doesn't make any sense.what does it mean?what do you want?

and here

var postLenght = $(this).val().lenght;

check the spelling of length


#4

Hi @arrayninja33611,

$('.status-box').val() = $('.status-box').val('');

The first half of that line (equal sign and before) is unnecessary. Calling .val(""); on a text input element will clear the element without you setting anything equal to the result of that operation.

You've also misspelled length several times :slight_smile:


#5

I want to count the characters left


#6

Now it works .
Thank you :slight_smile:


#7

This topic is solved.