Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

176
Vistas
JavaScript, What have I done wrong?

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.

if(args[0].length >= 4) {
  return msg.reply("Please use abbreviated time formats! **m**, **h**, **d**, **w**")
}
var data = args[0]
if(args[0].length = 3) {
  data = data.substr(0, 2) + " " + data.substr(2, 3);
  msg.channel.send(data);
}
else if(data.length = 2) {
  data = data.substr(0, 1) + " " + data.substr(1, 2);
  msg.channel.send(data);
  msg.channel.send("test")
}

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.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

This is an attempted assignment statement:

if(args[0].length = 3) {

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):

if(args[0].length == 3) {

And even better:

if(args[0].length === 3) {

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

about 4 years ago · Juan Pablo Isaza Denunciar

0

A single = is assign a value to a variable.

const name = 'John'
let age = 30

Double = is a comparison operator. It will transform the value to the same type before comparison.

console.log('1' == 1) // true

Triple = does the same thing but it won't transform the type. So the result is more accuracy.

console.log('1' === 1) // false

In most circumstances, stick with the triple =.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda