My problem with freeCodeCamp - Roman Numeral Converter

Tell us what’s happening:
Why are the “helpful hints” for the challenge so different to code solutions given?

I’ve spent a while typing out the code below (my fault), but felt there must be a better way.

Looking at even the basic solution, its so elegant yet there is no where that tells you how to write elegant code.

I guess I just want to rant.

But also want to ask, where can I learn about writing good code and coming up with elegant solutions?

Your code so far

function convertToRoman(num) {
  var numArr=[];
  var romArr=[];
  var ones=numArr[numArr.length-1];
  var romOnes=0; 
  if (ones==0) {
  } else if (ones>0 & ones<4) {
    for (i=0; i<ones-1; i++) {
      romOnes = romOnes + "I";
  } else if (ones==4) {
  } else if (ones==5) {
  } else if (ones>5 && ones<9) {
    for (i=0; i<ones-5; i++) {
      romOnes = romOnes + "I";
  } else if (ones==9) {
  if (numArr.length>1) {
    var tens=numArr[numArr.length-2];
    var romTens=0; 
    if (tens==0) {
    } else if (tens>0 & tens<4) {
      for (i=0; i<tens-1; i++) {
        romTens = romTens + "X";
    } else if (tens==4) {
    } else if (tens==5) {
    } else if (tens>5 && tens<9) {
      for (i=0; i<tens-5; i++) {
        romTens = romTens + "X";
    } else if (tens==9) {
   if (numArr.length>2) { 
    var hundreds=numArr[numArr.length-3];
    var romHundreds=0; 
    if (hundreds==0) {
    } else if (hundreds>0 & hundreds<4) {
      for (i=0; i<hundreds; i++) {
        romHundreds = romHundreds + "C";
    } else if (hundreds==4) {
    } else if (hundreds==5) {
    } else if (hundreds>5 && hundreds<9) {
      for (i=0; i<hundreds-5; i++) {
        romHundreds = romHundreds + "C";
    } else if (hundreds==9) {
 return num;


Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36.

Link to the challenge:

Not sure how to answer this question, but the helpful hints are just suggestions of functions and concepts you “could” use in a solution.

Not sure what you mean by “good code”, but elegant solutions come from experience and learning from other elegant solutions. When I say elegant, I mean the solution is readable (with variable names describing what the variable contains and function names which explain what the function does), DRY (not repetition of code), and efficient (no extra unnecessary looping or over use of memory resources).

Just keep practicing challenges and then rethinking and redoing the challenges until you come up with an elegant solution of your own. There are so many ways to solve most of these challenges.

1 Like

You do understand that your current solution above does not pass the tests?

Yes i know its unfinished. I felt frustrated at the point i stopped at and that was when I looked at the hints. I will try and finish it this way and then try ‘an elagent solution’ after.

Maybe i will start storing my various solutions on github to see my progress.

Thank you for this randell. Really puts things in perspective.

That is a fantastic idea. You could have branches for the different versions.