Roman Numeral Converter

A quick summary of my front end web project

Libor Marko
Jul 31 · 2 min read

This is a summary of my front end web project that converts any given number to a Roman numeral. Find the source code of this project on my GitHub profile.

Roman Numeral Converter

Programming Concepts Used

  • ES6

Technologies Used

  • JavaScript

How It Works

Roman numerals are a numeral system that comes from ancient Rome. Numbers in this system are represented by combinations of letters from the Latin alphabet.

I created a function that takes a given number and returns a roman numeral. I defined a variable lookup that contains an object with key/value pairs of the Roman numerals and their decimal equivalents.

I defined numbers represented by different letters in Roman numerals (I, V, X, L,…), and numbers that take place before a new letter is introduced (IV, IX, XL,…).

An empty string variable, romanized, will hold a final roman number. The for loop loops through the key/value pairs in the lookup object. If the while condition is met, the current i key is added to the variable romanized, and the num number is decreased by the current i value. The final roman number is returned as the result of the function.

Example: Let’s turn the number 654 into a Roman numeral.
1. I loop through the variable lookup to meet the while condition at i equals D:500 (let roman=D, let num=654–500=154).
2. loop: the while condition met at i equals C:100 (let roman=DC, let num=154–100=54).
3. loop: the condition met at i L:50 (let roman=DCL, let num=54–50=4).
4. loop: the condition met at i IV:4 (let roman=DCLIV, let num=4–4=0).


Better Programming

Advice for programmers.

Libor Marko

Written by

A self-taught web developer always curious about a new challenge. More about me on my linkedin and my web page: http://libormarko.github.io

Better Programming

Advice for programmers.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade