I have a list of articles with different categories (ex: aaa, bbb, ccc). I want to display the sum of the data-prices for each category
For example, I should have 3.20 for aaa, 10.20 for bbb, and 11.20 for ccc
const nombrearticle = 7;
for (let i = 0; i < nombrearticle; i++) {
if (data - categorie === aaa) {
totalquantiteaaa += Number(data - prix);
} else if (data - categorie === bbb) {
totalquantitebbb += Number(data - prix);
} else if (data - categorie === ccc) {
totalquantiteccc += Number(data - prix);
}
}
<a style="cursor: pointer; " data-prix="2.10" data-qte="1" data-categorie="aaa" onclick="setTimeout(() => ouvreMaJolieAlert(event), 1000);">ajouter au panier</a>
<a style="cursor: pointer; " data-prix="1.10" data-qte="1" data-categorie="aaa" onclick="setTimeout(() => ouvreMaJolieAlert(event), 1000);">ajouter au panier</a>
<a style="cursor: pointer; " data-prix="3.10" data-qte="1" data-categorie="bbb" onclick="setTimeout(() => ouvreMaJolieAlert(event), 1000);">ajouter au panier</a>
<a style="cursor: pointer; " data-prix="4.10" data-qte="1" data-categorie="" onclick="setTimeout(() => ouvreMaJolieAlert(event), 1000);"> ajouter au panier</a>
<a style="cursor: pointer; " data-prix="5.10" data-qte="1" data-categorie="ccc" onclick="setTimeout(() => ouvreMaJolieAlert(event), 1000);">ajouter au panier</a>
<a style="cursor: pointer; " data-prix="6.10" data-qte="1" data-categorie="ccc" onclick="setTimeout(() => ouvreMaJolieAlert(event), 1000);">ajouter au panier</a>
<a style="cursor: pointer; " data-prix="7.10" data-qte="1" data-categorie="bbb" onclick="setTimeout(() => ouvreMaJolieAlert(event), 1000);">ajouter au panier</a>
data-qteandonclickattributes aren't relevant to this specific problem, could you edit those out, just to minimise the code we're reading and parsing?<a>that doesn't have an attribute-value fordata-categorie? Also, please could you remove the attributes that don't appear to be relevant (thestyle,onclickanddata-qte)? If those attributes are all relevant to this, specific problem please could you explain how, and why?, but haven't definedaaa; should it be a string?if (data-categorie=== "aaa") {`?