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

165
Vistas
how do i continue the if function and to log all the results

I have a question about the If function , I want to continue condition 2 if the condition 1 is true and so on then at last will log all the results that have, but currently only will not continue if condition 1 is true here is the code:

       if (data1[0].themes[0].title) {
            message.channel.send(data1[0].themes[0].title)
            console.log(`1 sent`)
        } else if (data1[0].themes[1].title) {
            message.channel.send(data1[0].themes[1].title)
            console.log(`2 sent`)
        } else if (data1[0].themes[2].title) {
            message.channel.send(data1[0].themes[2].title)
            console.log(`3 sent`)
        }
         else message.channel.send(`no result`)
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Is this what you are trying to achieve? I am presuming the 'title' attribute holds some boolean value (You need a true or false value for the condition in the if statement). This will check each condition and send the message. If no data is sent, it will broadcast 'no result' in the channel.

let sent = false
if (data1[0].themes[0].title) {
    message.channel.send(data1[0].themes[0].title)
    sent = true
    console.log(`1 sent`)
}
if (data1[0].themes[1].title) {
    message.channel.send(data1[0].themes[1].title)
    sent = true
    console.log(`2 sent`)
}
if (data1[0].themes[2].title) {
    message.channel.send(data1[0].themes[2].title)
    sent = true
    console.log(`3 sent`)
}
if (!sent) {
    message.channel.send(`no result`)
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

It is conditional branch, you should move condition 2 inside the condition1

if(condition1) {
  if (condition2) {
  } else if (conditio3) {
  } else ...
} else {
}
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