0

I need help with defining a variable, I want to make a new variable named mainPendingTotal I want it to be equal to the pendingTotal if (x.Username == config.mainAccount) How do I do this? Below is code. It is not full code.

            .then(
                axios.spread((current, pending) => {
                    console.log(`${x.Username.cyan}\nCurrent: ${current.data.robux} R$\n${`Pending: ${pending.data.pendingRobuxTotal} R$`.gray}`);
                    if (x.Username == config.mainAccount) {
                        total.push(current.data.robux);
                        pendingTotal.push(pending.data.pendingRobuxTotal);
                    } else {
                        total.push(current.data.robux);
                        pendingTotal.push(pending.data.pendingRobuxTotal);
                    }
                })
            )
            .catch((message) => {
                console.log(`${x.Username}: Error ${message.response}`.red);
                total.push(0);
                pendingTotal.push(0);
            });
    }
    while (total.length !== file.length || pendingTotal.length !== file.length) {
        await new Promise((r) => setTimeout(r, 100));
    }
    let totalAdded = total.reduce((a, b) => a + b, 0);
    let pendingTotalAdded = pendingTotal.reduce((a, b) => a + b, 0);
    let allTotal = totalAdded + pendingTotalAdded;
    console.log(`${`\nTotal`.cyan}\nCurrent: ${totalAdded} R$\n${`Pending: ${pendingTotalAdded} R$`.gray}\n${`${allTotal} R$`.green}\n\nAfter Transfer: ${Math.round(allTotal * 0.7)} R$`);

I tried playing around with the code, making the variable being equal to what I already had for the if (x.Username == config.mainAccount), I was expecting it to be able to define it, but it ended up giving me an error.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • if (x.Username == config.mainAccount) { mainPendingTotal = pendingTotal }, is this what you want? – Alopwer Dec 27 '22 at 08:27
  • It's not clear what you want, share the error message – Alopwer Dec 27 '22 at 08:28
  • @Alopwer Sorry, I don't use javascript so I am unsure really of what I'm doing. I tried putting let mainPendingTotal = if (x.Username == config.mainAccount) { pendingTotal.push(pending.data.pendingRobuxTotal) } else { null } It gave the error SyntaxError: Unexpected token 'if' – Anthony Catalano Dec 27 '22 at 08:37
  • All the code in `.then()` runs asynchronously. You can't use those results outside the `.then()` function. – Barmar Dec 27 '22 at 08:37

0 Answers0