A fast, accessible calculator built with React, TypeScript, and Vite — no eval(), fully tested.
Table of Contents
This is the freeCodeCamp JavaScript Calculator project, rebuilt on a modern
stack. It started as a Create React App project and now runs on Bun, Vite, and
TypeScript. The unsafe eval() was replaced with a small hand-written parser,
and a typed-expression input was added on top of the usual keypad.
It is meant to be a calculator you actually reach for: mouse, touch, keyboard,
or a typed expression like (3 + 5) * 6 all work, results are accurate, and bad
input fails gracefully instead of breaking the page. All 15 freeCodeCamp user
stories pass.
System architecture:
Plus React Hook Form + Zod for the typed-expression input, and Testing Library for the component tests.
- Two ways in, one engine. Use the keypad, your physical keyboard, or type a full expression into a validated text field — all routed to the same evaluator.
- No
eval(). A tokenizer and recursive-descent parser handle operator precedence, unary minus, and parentheses safely. - Graceful errors. Divide-by-zero, malformed input, and overflow show a
recoverable
Error; an error boundary keeps the app from white-screening. - Validated input. Zod rejects stray characters and unbalanced parentheses; React Hook Form shows the message inline and disables submit until it's valid.
- Keyboard support. Digits,
+ - * /,Enter(=),Escape(clear), andBackspace. - Accessible.
aria-livereadout, labelled controls, visible focus rings, and a reduced-motion path. - Tested. 77 tests across the evaluator, formatter, schema, reducer, and the components (all 15 FCC user stories end-to-end).
- Bun v1.3 or newer
git clone https://github.com/omunite215/FCC-JavaScript-Calculator.git
cd FCC-JavaScript-Calculator
bun install
bun run devThe dev server runs at http://localhost:5173.
- Click the keys, or type on your keyboard.
- Or type a whole expression (e.g.
12 / 7) in the field and hit Evaluate. ACclears,⌫deletes the last entry.
Available scripts:
bun run dev # start the dev server
bun run build # type-check and build to dist/
bun run preview # preview the production build
bun run test # run the test suite
bun run lint # lint the source- Calculation history panel
- Percentage and sign-toggle keys
- Move to TypeScript 7 once typescript-eslint supports it
See the open issues for a full list of proposed features and known issues.
Contributions make the open-source community a great place to learn and build. Any contributions you make are greatly appreciated.
- Fork the project
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a pull request
Distributed under the MIT License. See LICENSE for more information.
Om Patel
Project link: https://github.com/omunite215/FCC-JavaScript-Calculator
- DwinaTech — the tutorial the original build followed
- freeCodeCamp — the project brief and test suite
- Best README Template
- Shields.io


