How can i minimize my app convert to roman

hello guys this is my code of chanllenge convert to roman ,it works but i want help to minimize it , this is the code

function convertToRoman(num) {

  var sum , res4, res5,res6,mod6

    if(num>0){

       res4 = Math.floor(num/1000);

       res4 = res4 *1000;

       let mod1 = (num%1000);

        res5 = Math.floor(mod1/100);

       res5 = res5 *100;

       let mod2 = (num%100);

        res6 = Math.floor(mod2/10);

       res6 = res6 *10

        mod6 =(num%10);

       sum = [res4,res5,res6,mod6];

  function unit(val){

    var x ;

    switch (val) {

  case 1:

    x = "I";

    break;

  case 2:

    x = "II";

    break;

    case 3:

    x = "III";

    break;

    case 4:

    x = "IV";

    break;

    case 5:

    x = "V";

    break;

    case 6:

    x = "VI";

    break;

    case 7:

    x = "VII";

    break;

    case 8:

    x = "VIII";

    break;

    case 9:

    x = "IX";

    break;

  default:

    x = "";

  }

  return x;

}

var u = unit(mod6);

function dizain(vale){

    var y ;

    switch (vale) {

  case 10:

    y = "X";

    break;

  case 20:

    y = "XX";

    break;

    case 30:

    y = "XXX";

    break;

    case 40:

    y = "XL";

    break;

    case 50:

    y = "L";

    break;

    case 60:

    y = "LX";

    break;

    case 70:

    y = "LXX";

    break;

    case 80:

    y = "LXXX";

    break;

    case 90:

    y = "XC";

    break;

  default:

    y = "";

  }

  return y;

}

var d = dizain(res6);

function centain(valeur){

    var k ;

    switch (valeur) {

  case 100:

    k = "C";

    break;

  case 200:

    k = "CC";

    break;

    case 300:

    k = "CCC";

    break;

    case 400:

    k = "CD";

    break;

    case 500:

    k = "D";

    break;

    case 600:

    k = "DC";

    break;

    case 700:

    k = "DCC";

    break;

    case 800:

    k = "DCCC";

    break;

    case 900:

    k = "CM";

    break;

  default:

    k = "";

  }

  return k;

}

var c = centain(res5);

function mill(va){

    var Z ;

    switch (va) {

  case 1000:

    Z = "M";

    break;

  case 2000:

    Z = "MM";

    break;

    case 3000:

    Z = "MMM";

    break;

    case 4000:

    Z = "MMMM";

    break;

    case 5000:

    Z = "V*";

    break;

    case 6000:

    Z = "VI*";

    break;

    case 7000:

    Z = "VII*";

    break;

    case 8000:

    Z = "VIII*";

    break;

    case 90:

    Z = "IX*";

    break;

  default:

    Z = "";

  }

  return Z;

}

var m = mill(res4) ;

}

return m + c + d + u;

}

console.log(convertToRoman((1000)));

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

@DanCouper
thanks for your comment and i’ll use backticks in my code here

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.