Roman Numerical Converter

Tutorials of (Roman numerical converter) by Victor hall

<!DOCTYPE html>
<html >
<head>
  <meta charset="UTF-8">
  <title>Roman Numerical Converter</title>
  
  
  
  
  
</head>

<body>
  <!--<div id="test"></div>-->
  
    <script  src="js/index.js"></script>

</body>
</html>
/* Downloaded from https://www.codeseek.co/ */
/* Downloaded from https://www.codeseek.co/ */
function convertToRoman(num) {
 
  var result = num;
  var answer = [];
  var temp = 0;
  
  
  //test if number is greater than or equal to 1000 
 if((result / 1000) >= 1){
    temp = result;
    //Returns how many times the number goes into 1000
    temp = temp / 1000;
    //rounds down to get a whole number
    temp = Math.floor(temp);
    //Adds that appropriate n quantities to the array
    for(var i = 0; i < temp; i++){
      answer.push("M");
    }
    //converts number in terms of 100 since there are not more 
   // 1000s left in it
    result = result % 1000;
  } 
  //This takes care of the special case
  //Since you cannot have 4 C's, this handles all 
  //numbers between 900 to 10000
  if((result < 1000) && (result >=900)){

    answer.push("CM");
    result = result  - 900;
  }
  
  
  //test if number is greater than or equal to 500
  if((result / 500) >= 1){
    temp = 0;
    temp = result;
     //Returns how many times the number goes into 500
    temp = temp / 500;
    //Rounds down
    temp = Math.floor(temp);
    
    for(var o = 0; o < temp; o++){
      answer.push("D");
    }
     //converts number in terms of 100 since there are not more 
   // 500s left in it
    result = result % 500;
  } 
  
  
  
  
  
if((result / 100) >= 1){
    temp = 0;
    temp = result;
    temp = temp / 100;
    temp = Math.floor(temp);
    
    for(var p = 0; p < temp; p++){
      answer.push("C");
    }
     
    result = result % 100;
  } 
  
   if((result < 100) && (result >= 90)){
    answer.push("XC");
    result = result - 90;
   
  }
  
  
if((result / 50) >= 1){
    temp = 0;
    temp = result;
    temp = temp / 50;
    temp = Math.floor(temp);
    
    for(var a = 0; a < temp; a++){
      answer.push("L");
    }
     
    result = result % 50;
  }
  
 
   if((result / 10) >= 1){
    
     temp = 0;
     temp = result;
     temp = temp / 10;
     temp = Math.floor(temp);
    
     if(temp > 3){
       answer.push("XL")
     }
     if(temp <= 3){
       for(var s = 0; s < temp; s++){
         answer.push("X");
       }
     }
     
     result = result % 10;

   }
  
  if(result == 9 ){
    temp = 0;
    answer.push("IX");
    result = result  % 9;
  }
  

  if((result / 5) >= 1){
    temp = 0;
    temp = result;
    temp = temp / 5;
    temp = Math.floor(temp);
    
    for(var f = 0; f < temp; f++){
      answer.push("V");
    }
     
    result = result % 5;
  }
  
  
  
  if((result / 1) >= 1){
     temp = 0;
     temp = result;
     temp = temp / 1;
     temp = Math.floor(temp);
    
    if(temp > 3){
      answer.push("IV")
    }
      
    if(temp <= 3){
        for(var g = 0; g < temp; g++){
        answer.push("I");
      }
    }
    
    
     
    result = result % 1;
  }
  
 var list = answer.join('');
 alert(list) 
 //document.getElementById('').innerHTML = answer;
 
}

convertToRoman(3999);

This awesome code ( Roman Numerical Converter ) is write by Victor Hall, you can se more from this user in the personal repository

You can find the original code on Codepen.io

2018 © Victor Hall