Metric-Imperial Converter
A small web app that converts between metric and imperial unit measures (Km/mi, Kg/lbs, L/gal).
I built this little website for freeCodeCamp’s first Information Security and Quality Assurance Projects.
The sample web app for this project was corrupted, but no problem, the files were still available on GitHub. After some time spent trying to make heads or tails of the boilerplate code, I got to work and banged the converter out. All in all, everything took me 17 hours to do and I felt even more energized and focused working on this project than usual.
User Stories
The brief for the Metric-Imperial Converter project was as follows:
- I will help prevent the client from trying to guess(sniff) the MIME type.
- I will prevent cross-site scripting (XSS) attacks.
- I can GET /api/convert with a single parameter containing an accepted number and unit and have it converted.
- Hint: Split the input by looking for the index of the first character.
- I can convert ‘gal’ to ‘L’ and vice versa. (1 gal to 3.78541 L)
- I can convert ‘lbs’ to ‘kg’ and vice versa. (1 lbs to 0.453592 kg)
- I can convert ‘mi’ to ‘km’ and vice versa. (1 mi to 1.60934 km)
- If my unit of measurement is invalid, returned will be ‘invalid unit’.
- If my number is invalid, returned with will ‘invalid number’.
- If both are invalid, return will be ‘invalid number and unit’.
- I can use fractions, decimals or both in my parameter(ie. 5, 1⁄2, 2.5⁄6), but if nothing is provided it will default to 1.
- My return will consist of the initNum, initUnit, returnNum, returnUnit, and string spelling out units in format
{initNum} {initial_Units}converts to {returnNum} {return_Units}
with the result rounded to 5 decimals.
- All 16 unit tests are complete and passing.
- All 5 functional tests are complete and passing.