Skip to content
Advertisement

JavaScript, What have I done wrong? [closed]

So, I’ve been messing around with this bit of code which I will eventually be moving into my mute command. I can’t seem to figure out what is wrong with this.

JavaScript

Basically, the first part where it sends a message if the length is 4 characters or more works. But, no matter how many characters below 4 are, it will always only run the if(args[0].length =3) part of the code. I’ve been trying to figure it out for the past hour and I don’t seem to know what is wrong with it. I must be blind or something.

Advertisement

Answer

This is an attempted assignment statement:

JavaScript

The evaluation of that expression is not only an unattended assignment, but it always evaluates to 3 which means it will always be true. That’s why this clause always runs regardless of the length of your argument.

This is probably what you meant (comparison, not assignment):

JavaScript

And even better:

JavaScript

Same mistake needs a correction for the else if(data.length = 2) { clause as well.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement