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

155
Views
Adiciones de Javascript

Tengo un código JS que escribí para agregar los valores de las variables, pero solo escribe los valores uno al lado del otro, no los agrega. ¿Cómo puedo sumar estos valores juntos?

JS:

 function display(){ let dollarvalue = `$ ${motorverseny}+${motorprofi}+${motoralap}+${turboverseny}+${turboprofi}+${turboalap}+${ecuverseny}+${ecuprofi}+${ecualap}+${valtoverseny}+${valtoprofi}+${valtoalap}+${felfuggesztesverseny}+${felfuggesztesprofi}+${felfuggesztesalap}`; let ppvalue = `${motorvenom}+${turbovenom}+${ecuvenom}+${valtovenom}+${felfuggesztesvenom}`; document.getElementById("pptext").innerHTML = `${ppvalue}`; document.getElementById("dollartext").innerHTML = `${dollarvalue}`; }

HTML:

 <h3 class="dollar">Dollar:</h3> <h5 id="dollartext" style="color: #7cc576;"></h5> <h3 class="pp">PP:</h3> <h5 id="pptext" style="color: blue;"></h5>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Esto se debe a que en realidad no está sumando los valores, sino que está utilizando la interpolación de cadenas de forma incorrecta. Debe colocar las variables entre llaves y sumarlas. Aquí hay un ejemplo:

 let var1 = 10; let var2 = 20; let dollarValueWrong = `$ ${var1}+${var2}`; // results in the string `$ 10+20` let dollarValueCorrect = `$ ${var1+var2}`; // results in the string `$ 30`
about 4 years ago · Juan Pablo Isaza Report

0

¿Qué hay de eliminar la interpolación?

 let ppvalue = motorvenom+turbovenom+…
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!