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

167
Vistas
How to add a tax rate to my cost under javascript?

I'm not sure how to add tax (7%) to my cost ($6) under Javascript. Can anyone help me?

html

<div class="item main">
<h1>Enter a Title</h1>
<p>Please enter a title to calculate how much it will cost<br>
<input id = "titleBox" type = "text">
<button onclick="calculateCost()">Enter</button> 
</p>
<p id= "output">Result</p>

    </div>

Javascript

var titleName;
var cost = 6;


function calculateCost() {

titleName = document.getElementById("titleBox").value;



var titleLetters; 
titleLetters = titleName.length;
var spaceCount = (titleName.split(" ").length - 1);
document.getElementById("output").innerHTML = "$" + (titleLetters - spaceCount) * cost;
/* "Red Car" "Red" "Car" */
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It is pretty basic(just simple math), here is the implementation:

    var titleName;
var cost = 6;
const tax = 7/100; // Added the tax

function calculateCost() {

titleName = document.getElementById("titleBox").value;



var titleLetters; 
titleLetters = titleName.length;
var spaceCount = (titleName.split(" ").length - 1);
document.getElementById("output").innerHTML = "$" + ((titleLetters - spaceCount) * cost*(1+tax)); // Since we have to add tax we have to use 1+tax
/* "Red Car" "Red" "Car" */
}

Note: scroll to the right to see the upgraded fromula since it got out of the stack overflow code box

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