Hi, I’m working on a code but unable to find a solution. Please help me. Actually, I need to find the sum of all the values for variable “interest”. Interest is calculated using the “rate” variable which comes from a for loop after checking the conditions.
if (wixUsers.currentUser.loggedIn) {
wixData.query("transfirm").eq("_owner", wixUsers.currentUser.id).eq("name", $item('#rate').value)
.find()
.then((results) => {
let queryItems = results.items;
queryItems.forEach((item, idx) => {
for (idx = 0; idx <= queryItems.length; idx++) {
if ($item('#text18').text === item.name) {
$item('#rate').text = item.rateofinterest;
var rate = parseFloat($item('#rate').text);
}
}
var days = (parseFloat(($item('#days').text)));
if (!isNaN(rate)) {
var myrate = parseFloat(rate);
var interest = parseFloat((principal * myrate * days) / 36000);
console.log(interest);
$item('#interest').text = interest.toString();
}
})
Now, I need total interest. I only put useful code because it’s little bit lengthy. Also, code is working perfectly. I’m considering: -
- to store the interest variable in array one by one but failed to do so.
- using reduce method; failed because array not formed.
I’ve tried a lot of methods but unable to get this. For a expert it may be just matter of few minutes. Looking forward to hearing from Velo community. Thanks in advance.