Hello. I want to submit a code stuff with an explanation. It is not a valid code. Someone can help me to find error?
<code>
** **
I'm trying to build a program that change numbers writen in decimal notation.
If we consider each ranges of numbers: unities, 10-es, 100-es and etc,
the pattern is the same.
If we take an array of characters ["a", "b", "c"], we have:
1 --> 'a',
2 --> 'aa',
3- --> 'aaa'
4 --> 'ab',
5 --> 'b',
6 --> 'ba',
7 --> 'baa',
8--> 'baaa',
9-->'ac'.
0 -->''
Now we have as representations of abc:
('I', 'V', 'X');
('X', 'L', 'C');
('C', 'D', 'M');
('M', V with upperscore, X with upperscore ) and etc.
The principe is the same, we need a strategy to replace the combinations
of abc by the roman numeral symbols.
I think that, e.g. if we take the number 257,
The first step is to convert the number to string ‘257’.
The second step is to slplit the string in an array
var list = [‘2’, ‘5’, ‘7’]. his length is “l”.
The third step is to looping through this array and replace
the list [l-1] characters following the first representation of abc,
the next, list [l-2] up to [0] replaced as this.
the fourst step is to join the modified list with .join(‘’).
You can see the Code and if you help me to debugging I'll be grateful!*/
function hitboleloute(num){//1e parenthese
// Create a bidimentionnal list that contain successives degree of a same
// principle.
var superlist = [["a", "I","X","C", "M"], ["b", 'V', 'L', "D"],
["c", "X", "C", "M"]]
1.//the first step num to string.
2.var letter1 = num.toString();
3.
4.//the second step string to array
5.var letter3 = letter1.split('');
6.var l = letter3.length;
7.
8.//the third step looping through array and replace digit-string by letter
9.//of symbolic value.
10.for(i = 0; i < l; i++ ) {// 2e parenthese
11. var item = letter3[i];
12. if(item === '1') {item = 'a'}
13. else if (item === '2') {return "aa"}
14. else if (item === '3') {return "aaa"}
15. else if (item === '4') {return "ab"}
16. else if (item === '5') {return "b"}
17. else if (item === '6') {return "ba"}
18. else if (item === '7') {return "baa"}
19. else if (item === '8') {return "baaa"}
20. else if (item === '9') {return "ac"}
21. else if (item === '0') {return ""}
22.}//2e parenthese closed
23.// the letter3 array should be an array of symbolic letters
24.console.log(letter3);
25.// trying to replace a,b and c by realy roman numerals
for (x = 0; x<4; x++){//new 2e parenthese
for (j = l -x; j > -1; j --) {//3e parenthese
var jtem = letter3[j];
if (j == l-x) {for (k=0; k<item.length; k++) {//4e parenthese
if (jtem[k] === 'a') {
return superlist[0][x];
}
if (jtem[k] === 'b') {
return superlist[1][x];
}
if (jtem[k] === 'c') {
return superlist[2][x];
}
}//4e parenthese closed
}//3e parenthese closed
}//new 2e parenthese closed
return jtem;
}//1e parenthese closed
// a list of roman numerals
return letter3
}
hitboleloute(36);</code>