Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!