DEV Community

Arhan Khan
Arhan Khan

Posted on

Build a Tip Calculator App with JavaScript

A tip calculator is one of the best first projects for a JavaScript beginner. It is a real tool people actually use, and it teaches the three skills every interactive app needs: reading input, doing a calculation, and showing the result.

The app is simple. The user enters the bill amount, picks a tip percentage, and optionally splits the bill between people. The app shows the tip amount, the total, and how much each person pays.

<input id="bill" type="number" placeholder="Bill amount (₹)">
<select id="tip">
  <option value="0.10">10%</option>
  <option value="0.15" selected>15%</option>
  <option value="0.20">20%</option>
</select>
<input id="people" type="number" value="1" min="1">
<button onclick="calculateTip()">Calculate</button>
<p id="result"></p>
Enter fullscreen mode Exit fullscreen mode
function calculateTip() {
  const bill = Number(document.getElementById('bill').value);
  const tipRate = Number(document.getElementById('tip').value);
  const people = Number(document.getElementById('people').value) || 1;

  const tip = bill * tipRate;
  const total = bill + tip;

  document.getElementById('result').textContent =
    `Tip: ₹${tip.toFixed(2)} | Total: ₹${total.toFixed(2)} | ` +
    `Each person pays: ₹${(total / people).toFixed(2)}`;
}
Enter fullscreen mode Exit fullscreen mode

Why build this? It is small enough to finish in an evening, but it forces you to handle the details that trip beginners up: empty inputs, dividing by zero people, and rounding money to two decimals. The || 1 fallback for people and toFixed(2) for money are small lines that teach real habits.

A few ideas to extend it: add buttons for 10%, 15%, and 20% instead of a dropdown, let the user type a custom tip, or round the total up to the nearest ₹10. Each one is a small feature and a good next lesson.

Build it, style it with a little CSS, and keep it on your phone's home screen. A project you actually use is worth ten tutorial projects you never open again.

Top comments (0)