Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
john larson
16,594 PointsWorking on at outside project cause I need a break from the jquery course. Getting a var not defined error
It seems to work as intended until I add the if statement near the bottom
var main = function(){
$(".btn").click(function(){ /* .val() like.text() for form inputs */
var post = $(".status-box").val(); /* entered text stored in post */
$("<li>").text(post).prependTo(".posts"); /*create li + txt + prepend*/
$(".status-box").val(""); /* clear status box */
$('.counter').text('140'); /* reset counter at btn click */
});
$(".status-box").keyup(function(){ /* count at each upstroke */
var postLength = $(this).val().length; /* char in status-box */
var charectersLeft = 140 - postLength; /* total - strokes */
$(".counter").text(charectersLeft); /* display total */
// this works fine until if statement
// then I get an error charactersLeft not defined
// maybe be something else I'm missing
// cause charactersLeft seems to be working
// prior to addition of the if statement
if(charactersLeft < 0){
$(".btn").addClass("disabled");
} else if(charactersLeft === 140){
$(".btn").addClass("disabled");
} else{
$(".btn").removeClass("disabled");
}
}); /* keyup event */
// $(".btn").addClass("disabled");
}
3 Answers
Jennifer Nordell
Treehouse TeacherHi there! You've been stung by the typo monster!
var charectersLeft = 140 - postLength; /* total - strokes */
$(".counter").text(charectersLeft);
Here, you've spelled it "charecters" instead of "characters" in two places But then you have it spelled correctly here:
if(charactersLeft < 0){
$(".btn").addClass("disabled");
} else if(charactersLeft === 140){
Hope this helps!
Cindy Lea
Courses Plus Student 6,497 PointsShould this statement below have == and not === ?
else if(charactersLeft === 140){
john larson
16,594 PointsThey use == but I thought === would be safe to use
Jennifer Nordell
Treehouse Teacherjohn larson It is perfectly safe :) The triple equals means explicitly equal to or identical.
Jeremiah Bushau
24,061 PointsOnly thing i see at first glance is a simple typo
var charectersLeft = 140 - postLength // typo on word 'characters'
john larson
16,594 PointsThank you
john larson
16,594 Pointsjohn larson
16,594 PointsThanks, I thought i used copy and paste but apparently not.