Roman numerals challenge (implementing 24/39... numbers)

Roman numerals challenge (implementing 24/39... numbers)
0

#1

Hello, in the roman numerals intermediate algorithm scripting challenge, I could analyze the pattern and this is what I reached:

function convertToRoman(num) {
  var numlist = {1:'I',5:'V',10:'X',50:'L',100:'C',500:'D',1000:'M',
                 4:'IV',9:'IX',40:'XL',90:'XC',400:'CD',900:'CM'};
  if (!numlist[num]) {
     numlist[num] =
    numlist[1000].repeat((num%10000-num%1000)/1000)+
    numlist[500].repeat((num%1000-num%500)/500)+
    numlist[100].repeat((num%500-num%100)/100)+
    numlist[50].repeat((num%100-num%50)/50)+
    numlist[10].repeat((num%50-num%10)/10)+
    numlist[5].repeat((num%10-num%5)/5)+
    numlist[1].repeat((num%5-num%1)/1);
  }
return numlist[num];
}
convertToRoman(40);

I can’t wrap my mind around the way to implement the 24,39 etc… Can you please tell me what am I getting wrong? I don’t want to see the full answer on the fcc wiki on github. So can you please give me hints and not give away the whole answer.

Also, side question. I started with free code camp 8 days ago and I finished all the challenges until the intermediate algorithm scripting (I am unemployed so I work on the site for about 8 hours a day or more). and I find that I it’s hard for me to comprehend everything. Does it take some talent to be a programmer, I mean should I by now be able to grasp the concepts easily or am I just putting unrealistic goals to myself (It is my goal to get a job as a web developer in a month/three weeks by now).


#2

Here is a possible tip for your solution: if num uses ‘IX’ it must end in a 9 and can’t be followed by ‘V’ or ‘I’. If a number uses ‘IV’ it must end in a 4 and can’t be followed by in an ‘I’. So hitting a case where you use numlist[9] or numlist[4] means that you don’t have to concatenate anything else to the string. I haven’t seen a solution quite like yours worked out entirely, but it seems like the way to do it would be to recognize those values as terminal.

As to your side question: There is no innate talent that you need to be a programmer. Some of us take to it faster or slower than others because of how our education or background has prepared us for this type of problem solving, but that’s comes out in the wash over time. @QuincyLarson wrote One Does Not Simply Learn To Code because coding is hard to learn (although I did make this rebuttal at the time).

The fact that you’ve been able to go through FCC so steadily might be over-saturating your brain a bit so remember to take regular breaks and to go back and review earlier challenges. Also try to resist moving forward as quickly as you can. The growing checkmarks are very satisfying, but you’ll get more value by spending some time tinkering with your solution and testing that you really know what you did and why.


#3

Thank you ArielLeslie, I think I may be doing it the hard way I’ve always done maths the hard way going through equations from hell and high level maths to solve easy problems, it’s just my nature and I’m trying to defeat that. This tip is very helpful, I am going to simplify the code and implement that and see where it leads me.
About my education I actually have a degree in architecture, but I decided to return to what I loved most, that is programming. Yes I think I’m taking it too fast, can’t say I’m not happy to finish all that in just 8 days I mean html, css, javascript, jquery, some algorithm scripting, bootstrap, all those challenges in FCC, my mind is strained now yea but I think I’ll turn back to some earlier problems and return to watching mini-courses on web dev. Thanks for your help :slight_smile: