# JavaScript Algorithms and Data Structures Projects - Roman Numeral Converter

This is first serios task for me. I try so hard, but it looks like i must finish all theory first)

``````function convertToRoman(num) {
const numbers = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X'];
const numbersTen = ['X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', 'C'];
const numbersHundred = ['C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', 'M']
let array = ("" + num).split("");
let romanNum;
if (array.length === 1) {
romanNum = numbers[num - 1];
} else if (array.length === 2) {
let a = array[0];
let b = array[1];
if (b === 0) {
romanNum = numbersTen[a-1]} else {
romanNum = numbersTen[a-1] + numbers[b-1];
}
} else if (array.length === 3) {
const a = array[0];
const b = array[1];
const c = array[2];
if (a !== 0 && b !== 0 && c !== 0) {
romanNum = numbersHundred[a-1] + numbersTen[b-1] + numbers[c-1];
console.log(romanNum)
}
if (c === 0) {
romanNum = numbersHundred[a-1] + numbersTen[b-1]
console.log(romanNum)
}

}
return romanNum;

}

convertToRoman(36);
``````

User Agent is: `Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36`