Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
Javascript additions

I have a JS code whitch I wrote to add the values of variables together, but it just writes the values next to each other, it does not add them together. How to I add these values together?

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 Respuestas
Responde la pregunta

0

This is because you're not actually summing the values, but you are using string interpolation incorrectly. You need to place the variables within the curly braces and sum them. Here is an example:

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 Denunciar

0

How about removing the interpolation?

let ppvalue = motorvenom+turbovenom+…
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda