Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

291
Views
calcular valores dentro de un bucle for

como un novato en JavaScript. Estoy tratando de obtener el precio total de cada producto.

 <div class="product"> <span class="name">product 1</span> <span class="price">25.00</span> </div> <div class="product"> <span class="name">product 2</span> <span class="price">45.00</span> </div> <div id="cart-total"></div>

Y este es mi código... ¿qué estoy haciendo mal?

 const products = document.querySelectorAll(".product"); const productName = document.querySelectorAll(".name"); const productPrice = document.querySelectorAll(".price"); const cartTotal = document.querySelector("#cart-total"); let total = 0; for (i = 0; i < products.length; i++) { const productPriceValue = parseInt(productPrice[i].innerText); total += productPriceValue; } console.log(total) // prints 70 where i need it to print 70.00
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Además de convertir int a float, debe definir el valor total por encima de la iteración, se convierte en 0 en cada elemento.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!