@Charlesxstorm (Charles Ukadike) posted a new topic, subject "Will this pass as a clean code ? ( Roman Numeral Converter )". It read:

   freecodecamp.org
    
    ### freeCodeCamp.org
    
    Learn to Code — For Free
    
    Here's my code for the challenge, It could have been shorter:
    [code] 
        function convertToRoman(num) {
         const word1 = {1:'I',2:'II',3:'III',4:'IV',5:'V',6:'VI',7:'VII',8:'VIII',9:'IX'};
         const word2 = {1:'X',2:'XX',3:'XXX',4:'XL',5:'L',6:'LX',7:'LXX',8:'LXXX',9:'XC'};
         const word3 = {1:'C',2:'CC',3:'CCC',4:'CD',5:'D',6:'DC',7:'DCC',8:'DCCC',9:'CM'};
         const word4 = {1:'M',2:'MM',3:'MMM'};
        
         const inp = String(num).split('');
        
         switch(inp.length){
        
         	case 1:
         		return word1[Number(inp[0])];
         	case 2:
         		if (inp[1] == '0'){
         			return word2[Number(inp[0])];
         		}else{
         			return word2[Number(inp[0])] + word1[Number(inp[1])]
         		}
         	case 3:
         		if (inp[1] == '0' && inp[2]=='0'){
         			return word3[Number(inp[0])];
         		}else if (inp[1] == '0') {
         			return word3[Number(inp[0])] + word1[Number(inp[2])];
         		}else if (inp[2] == '0') {
         			return word3[Number(inp[0])] + word2[Number(inp[1])];
         		}else{
         			return word3[Number(inp[0])] + word2[Number(inp[1])] + word1[Number(inp[2])];
         		}
        
         	case 4:
         		if (inp[1] == '0' && inp[2]=='0' && inp[3]=='0'){
         			return word4[Number(inp[0])];
         		}else if (inp[1] == '0' || inp[2]=='0'){
        
         			if (inp[1] == '0' && inp[2]=='0'){
         				return word4[Number(inp[0])] + word1[Number(inp[3])];
         			}else if (inp[1] == '0'){
         				if (inp[3] == '0'){
         					return word4[Number(inp[0])] + word2[Number(inp[2])];
         				}else{
         					return word4[Number(inp[0])] + word2[Number(inp[2])] + word1[Number(inp[3])];
         				}
         			}else{
         				if (inp[3] == '0'){
         					return word4[Number(inp[0])] + word3[Number(inp[1])];
         				}else{
         					return word4[Number(inp[0])] + word3[Number(inp[1])] + word1[Number(inp[3])];
         				}
         			}
        
         		}else{
         			return word4[Number(inp[0])] + word3[Number(inp[1])] + word2[Number(inp[2])] + word1[Number(inp[3])];
         		}
        
         }
        
        }
        
    [/code]

To which @JeremyLT (Jeremy) replied

    Good job getting the challenge solved! This is a tricky one.
    
    For improvement, you still have a lot of repetition. If you have a lot of code that does very similar stuff, I would start looking at loops to replicate the same action many times.

To which @Charlesxstorm (Charles Ukadike) replied

    Thank you for the feedback, I'll definitely check up more on loops.


{'source': 'discourse', 'url': 'https://forum.freecodecamp.org/t/will-this-pass-as-a-clean-code-roman-numeral-converter/515293', 'title': 'Will this pass as a clean code ? ( Roman Numeral Converter )', 'views': 62, 'has_accepted_answer': False, 'word_count': 371, 'like_count': 0, 'reply_count': 1, 'participant_count': 2, 'posts': 3, 'tags': '', 'author': '@Charlesxstorm (Charles Ukadike)', 'participants': '@Charlesxstorm (Charles Ukadike), @JeremyLT (Jeremy)', 'image_url': [None], 'created_at': '2022-06-06T20:51:30.311Z', 'last_posted_at': '2022-06-06T21:23:00.002Z'}