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.
![](https://static.wixstatic.com/media/a27d24_028db0a6eba74c7890e8d8fe477b7e47~mv2.png/v1/fill/w_473,h_365,al_c,q_85,enc_auto/a27d24_028db0a6eba74c7890e8d8fe477b7e47~mv2.png)
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.
![](https://static.wixstatic.com/media/a27d24_b4ec23fc27cd422f88e1d76aaf7b2c0b~mv2.png/v1/fill/w_373,h_63,al_c,q_85,enc_auto/a27d24_b4ec23fc27cd422f88e1d76aaf7b2c0b~mv2.png)
Second, I then have the "completePrice" add the "Price" and itself each time the function runs so that I can get total price.
![](https://static.wixstatic.com/media/a27d24_56091a6b723c41799c0fdaa6964d45ed~mv2.png/v1/fill/w_453,h_223,al_c,q_85,enc_auto/a27d24_56091a6b723c41799c0fdaa6964d45ed~mv2.png)
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
Yisrael,
Thank you so much! It has taken me so much time to figure that out and I just needed to delete "let"!
- Jack
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
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) })} )
Can you post the full code and/or provide link
David,
Thanks for the input, but I've tried that already. Any other ideas?
Jack
Simple solution I'm sure you've tried but maybe convert it to an actual number then try running the math?
Number(*yournumber*);