Add the price from a repeater

I am creating a website with a summary container box. On the container box, I would like to summarize a customer order according to the service they wanted.

One of the inputs is selection tags that connect to a repeater, showing name and price.

Now, When I try to add the value of the repeater using the code below, it doubles or triple the price of the item

function setRepeatedItemsInRepeater() {
var tagConcat;
const selectedTags = $w( ‘#selectionTags1’ ).value;
let nr = selectedTags.length;
let sum = 0 ;

$w( ‘#repeater1’ ).onItemReady(($item, itemData) => {
$item( ‘#extraSvcTitle’ ).text = itemData.shortName;
$item( ‘#extraCSvcPrice’ ).text = String(parseFloat(itemData.price).toFixed( 2 ));

for ( var i = 0 ; i <= nr; i ++) {

    sum += parseFloat(itemData.price); 
    $w( '#text190' ).text =  String(sum); // here is the big text file in the screenshot 
}    

}) 

}

let dataQuery = wixData.query(collectionName);

if (selectedCategories.length > 0 ) {
dataQuery = dataQuery.hasSome(fieldToFilterByInCollection,selectedCategories);
}

dataQuery 
    .find() 
    .then(results => { 

// const cnt = results.totalCount;
const itemsReadyForRepeater = results.items;
$w( ‘#repeater1’ ).data = itemsReadyForRepeater;
const isRepeaterEmpty = itemsReadyForRepeater.length === 0
// $w(‘#text191’).text = String(cnt);

    }) 

}

$w( ‘#selectionTags1’ ).onChange((event) => {
$w( “#repeater1” ).show();
const selectedTags = $w( ‘#selectionTags1’ ).value;

if (selectedTags.length === 0 ) {
$w( “#repeater1” ).hide();
}
else {

        loadDatatoRepeater(selectedTags);  
        setRepeatedItemsInRepeater(); } 

     }) 

});

I concatenated the price in a string and saw that it is indeed double and sometimes tripled (more than) (ignore the undefined it’s just a variable I didn’t define).

Can someone help? Thanks!

Hello and happy new year!

I think this is the code-part which makes problems.

for(var i = 0; i <= nr; i ++) {        sum += parseFloat(itemData.price);        $w('#text190').text =  String(sum); // here is the big text file in the screenshot    }

You have several selected TAGs which you define in a variable called (nr)

let nr = selectedTags.length;

nr = the length of your TAG-selections. So if you have 2 or 3 selected TAGs, then you will get also the same amount of loops in your for-loop.
This doubles or triples your SUM.

But what you want is to get the right price out of the current selected TAG, right? You should tryy something like…

for(var i = 0; i <= nr; i ++) {
    sum += parseFloat(itemData[i].price);
    $w('#text190').text =  String(sum);
}

or

for(var i = 0; i <= nr; i ++) {
    sum += parseFloat(itemData.price[i]);
    $w('#text190').text =  String(sum);
}