step7 why does an error in the ELSE sentence affects the whole js


#1

I have made a mistake by putting a () after the ELSE like below

       if(charactersLeft < 0) 
            {$('.btn').addClass('disabled')}
       else if(charactersLeft==140)
            {$('.btn').addClass('disabled')}
       else ()
           {$('.btn').removeClass('disabled')}
});
$('.btn').addClass('disabled');

Why the 'post' button and 'counter' does not work anymore? It seems the keyup function is sabotaged.
And then I change the () to {}, the $('.btn').removeClass('disabled') works, but the $('.btn').addClass('disabled') does not work. They are not in a same function. Is the ELSE in a loop now?
Thanks


#2

Why do you add the brackets after the else?

       else () //delete the ()
           {$('.btn').removeClass('disabled')}

#3

Hi Dynamitezhang,

You need to remove everything except the else on that line, and I think your code will work :)
If not, could you please post the rest of it? Thanks!


#4

Hi Dookoo-de, i add the brackets by mistake, and I know it. But I want to know why the ELSE segment affects the whole javascript. Thanks.


#5

Hi zystvan, i add the brackets by mistake, and I know it. But I want to know why an error in the ELSE segment affects the whole javascript. Thanks.


#6

@dookoo_de Weird - I didn't see your reply when I posted, even though you replied several hours before me :confused:

@dynamitezhang Which $('.btn').addClass('disabled') are you asking about?