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

179
Views
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 answers
Answer question

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 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!