Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

169
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda