Skip to content

JavaScript Project: Build a Tip and Bill Split Calculator (English and Arabic)

NeedMyTools Academy

Sign in free to read the full lesson

Sign in or create a free account

Free forever. No card, no paywall.

A group of friends finishes dinner in Dubai. The bill is 387.50 dirhams, they want to add 10 percent and split it between three people, and one of them types the amount on a phone with an Arabic keyboard. In this project you build the calculator that handles all of that properly. It uses nearly every lesson in the course: variables and types, conditions, functions, objects, the DOM, events, modules and debugging. It ends with a tool you could put on your own site, and the same approach, with tested and careful maths, is how the calculators on this site are built.

Quick answer

Build it in five steps. Write an accessible form with labels and an <output aria-live="polite">. Write a toNumber function that trims the text, turns Arabic digits and the Arabic decimal sign into Western ones and returns NaN for anything else. Do the maths in whole fils, Math.round(bill * 100), add the tip, then split so the shares add up exactly to the total. Format every amount with new Intl.NumberFormat(locale, options) and the options style: "currency" and currency: "AED". Recalculate on every input event and write results and error messages with textContent.

50 min read and practice · Content checked on 15 November 2026

In this lesson you will

  • Plan a small tool as inputs, rules and outputs before writing code
  • Read messy input safely, including Arabic digits and commas
  • Calculate money in whole fils and split a total fairly
  • Show results in English or Arabic with Intl.NumberFormat and test the finished tool

Step 1: plan inputs, rules and outputs

Before any code, write three short lists. Inputs: the bill amount, the tip as a percentage, the number of people and the language. Rules: the bill must be a number above 0 and at most 100,000; people must be a whole number from 1 to 50; a tip of 0 is allowed. Outputs: the tip, the new total and the amount per person, plus one clear message when an input is wrong. These lists become your functions and your tests, and they stop you from discovering half-way through that you never decided what happens with 0 people.

Then write the HTML from the HTML course: a <form> with a <label> around every field, inputmode="decimal" so phones show a number keyboard with a decimal point, a <select> for the tip so nobody types "10%" by hand, and an <output> with aria-live="polite" so screen readers announce new results. Add novalidate to the form, because your own checks will give better, bilingual messages than the browser’s. Restaurants in the Gulf often add a service charge already, so a "No tip" choice is a real option, not an afterthought.

Try it: The form, ready for code
Code
ResultUpdates as you type
Console
  1. Console messages, errors, form data and clicked links appear here.

Type in the boxes and change the selects. Object.fromEntries(new FormData(form)) turns the whole form into one object of strings, which is exactly what the next step has to clean up.

Sign in free to read the full lesson

You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.

Unlocks after sign-in:

  • 4 more sections with live code examples
  • Common mistakes to avoid
  • Hands-on coding exercise with automatic checks
  • Practice quiz and the graded lesson test
Sign in or create a free account

Free forever. No card, no paywall.

Questions people ask

How do I convert Arabic digits to English numbers in JavaScript?

Replace each digit from ٠ to ٩ with its position in the string "٠١٢٣٤٥٦٧٨٩", using replace with a regular expression and a function, and turn the Arabic decimal separator into a dot. Do the same for Persian digits if your visitors use them, then call Number on the result.

How do I format a number as dirhams or riyals in JavaScript?

Create new Intl.NumberFormat(locale, options) with the options style: "currency" and currency: "AED", then call .format(amount). Use "SAR" for riyals, "QAR", "KWD", "BHD" or "OMR" for the other Gulf currencies; Kuwaiti, Bahraini and Omani amounts get three decimals automatically.

Should I add a tip when the bill already has a service charge?

That is a personal choice, and the calculator should not decide it. Read the bill first: if it shows a service charge, many people choose a small tip or none, which is why "No tip" is the first option in this project.

What should I learn after this JavaScript course?

Build two or three tools of your own first, then pick one direction. TypeScript adds types that catch many bugs before they run. A framework such as React helps with larger interfaces. Node.js lets you write servers and APIs in the same language.

Where can I publish a small JavaScript tool for free?

A tool made of HTML, CSS and JavaScript files is a static site, so free static hosts such as GitHub Pages, Cloudflare Pages and Netlify can serve it. Read each host’s current free plan limits before you rely on it.

Sources

Facts in this lesson were checked against these official pages on 15 November 2026.

Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.