Tell us what’s happening:
All the tests pass / produce the desired outcomes.
I’ve console.logged “expected result” and “result” side by side - for all your tests & all match.
How come not all pass on the platform?
Your code so far
function convertToRoman(num) {
let conv1 = {
1: "I", 2: "II", 3: "III", 4: "IV", 5: "V",6: "VI",7: "VII",8: "VIII", 9: "IX"
}
let conv2 = {
1: "X", 2: "XX", 3: "XXX", 4: "XL", 5: "L", 6: "LX", 7: "LXX", 8: "LXXX", 9: "XC"
}
let conv3 = {
1: "C", 2: "CC", 3: "CCC", 4: "CD", 5: "D", 6: "DC", 7: "DCC", 8: "DCCC", 9: "CM"
}
let conv4 = {
1: "M", 2: "MM", 3: "MMM", 4: "MMMM", 5: "V", 6: "VM", 7:"VMM", 8: "VMMM", 9: "VMMMM"
}
let len = String(num).length
let thing = String(num)
if (len === 1){
for (let i in conv1){if (i === thing){return conv1[i]}}
}
if (len === 2){
let res = []
for (let i in conv2){if (i === thing[0]){res.push(conv2[i])}}
for (let i in conv1){if (i === thing[1]){res.push(conv1[i])}}
return res.join("")
}
if (len === 3){
res = []
for (let i in conv3){if (i === thing[0]) {res.push(conv3[i])}}
for (let i in conv2){if (i === thing[1]) {res.push(conv2[i])}}
for (let i in conv1){if (i === thing[2]) {res.push(conv1[i])}}
return res.join("")
}
if (len === 4){
res = []
for (let i in conv4){if (i === thing[0]) {res.push(conv4[i])}}
for (let i in conv3){if (i === thing[1]) {res.push(conv3[i])}}
for (let i in conv2){if (i === thing[2]) {res.push(conv2[i])}}
for (let i in conv1){if (i === thing[3]) {res.push(conv1[i])}}
return res.join("")
}
}
convertToRoman(36);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36
.
Challenge: Roman Numeral Converter
Link to the challenge: