Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
problem with display of quantity on a cart html page using js

thank you for your previous help, now the toal quantity works perfectly. i have tried to aplly the same principle with the total price but it displays "nan" (" price += parseInt(monPanier[i].price);"). before adding this line, the total price diplayed was only one copy per item even eg there was two black items, 3 red items and 4 yellow, it was considered as total price one black + one red + one yellow. Thank you for your help.

 let asynCompteur = 0;
    let quantity = 0;
    let price = 0;
    for (let i = 0; i < monPanier.length; i++) {
        fetch('http://localhost:3000/api/products/' + monPanier[i].id)/*appel de l'api*/
        .then((reponse) => reponse.json())
        .then((data) => { 
            /*asynCompteur pour réguler l'itération*/
            asynCompteur = asynCompteur + 1;              
            //J'ajoute le prix et la quantité
            quantity += parseInt(monPanier[i].quantity);                price += data.price;
            console.log('prix', asynCompteur, price, quantity);
            price += parseInt(monPanier[i].price);
            console.log(typeof monPanier[i].quantity);
            if (asynCompteur === monPanier.length) {
                document.querySelector("#totalQuantity").innerText = quantity;
                document.querySelector("#totalPrice").innerText = price; 
            }

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

it works partially. The quantity is updated correctly and follow the changes of the cart.So, the display of total quantity is correct.But... strangely, the total price consider only one of each item, it means: ie black item (2 times), yellow item (3 times), red item (2 times), total quantity displayd: 7 (correct), total price: incorrect(it displays total price of one black item + one yellow item + one red item. Thank you for your precious help.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda