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`)
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`)
}
It is conditional branch, you should move condition 2 inside the condition1
if(condition1) {
if (condition2) {
} else if (conditio3) {
} else ...
} else {
}