Hi all!
I’m having an issue with adding values up from a repeater. So far I have been able to take data from a database, add it to a repeater and have the repeater output a price with the aspects of the product and the quality taken into account.
My issue is I can’t get the total price with all the prices in the repeater added up.
So far I have tried this code below.
First, I define “completePrice = 0” outside the function so that it is a value and not a string.
Second, I then have the “completePrice” add the “Price” and itself each time the function runs so that I can get total price.
I’ve spent countless hours trying to get this to work but the price just keeps saying “NaN”
Anyone know how I can fix this?
Thank you for your help in advance!
Jack
Simple solution I’m sure you’ve tried but maybe convert it to an actual number then try running the math?
Number(*yournumber*);
David,
Thanks for the input, but I’ve tried that already. Any other ideas?
Jack
Can you post the full code and/or provide link
David,
Below is all the code. Hopefully you can find an issue!
let completePrice = Number(0);
$w.onReady( function () {
$w(“#orderlist”).onItemReady(($w, itemData, index) => {
let quantity = Number(itemData.quantity)
//other items gathered from the item list are pulled here
let iD = 0;
if (title === ‘Medium’) { iD = 1;}
else if (title === ‘Intermediate’) { iD = 2;}
else {iD = 3;}
// More code that gives the iD is written here
const getPrice = (iD) => {
if (iD === 11111) { return 111.11;}
else if (iD === 11112) { return 111.12;}
//There's a bunch of code to pricing lines here that I removed
else if (iD === 25433) { return 111.12;}
}
$w('#price').text = String(getPrice(iD))
$w("#totalPrice").text = String(getPrice(iD)*quantity)
let completePrice = completePrice + getPrice(iD)*quantity;
$w(“#completePrice”).text = String(completePrice + getPrice(iD)*quantity)
})}
)
The code pane shows a couple of warning messages. One in particular is a BIG hint…
You already have completePrice declared as a global variable. By declaring it as a local in the onItemReady() function means that the values aren’t added.
Delete the let so your line of code looks like this:
completePrice = completePrice + getPrice(iD) * quantity;
I would also recommend changing the variable iD (indicated in the screen shot) to something unique just to avoid possible conflicts.
I hope this helps,
Yisrael
Yisrael,
Thank you so much! It has taken me so much time to figure that out and I just needed to delete “let”!