problem
the value of affiliateXp dont show outside of the .foreach
code:
//get affiliateXp
let affiliateXp = 0
let invitedUsers = await userSchema.find({
invitedById: userID
})
invitedUsers.forEach(async user => {
let userXp = await getXpPerUser(user.discordId)
affiliateXp = await affiliateXp + 1000 + userXp.totalXp*0.1
console.log ('inside', affiliateXp)
});
console.log ('outside', affiliateXp)
console:
outside 0
outside 0
inside 1000.1073925
outside 0
inside 2000.1073925
outside 0
inside 3002.3100682
outside 0
inside 1000