Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                
  function convertToRoman(num) {
    //create object of decimal to roman key/values
    var numConvertor = {
      1000: 'M',
      900: 'CM',
      500: 'D',
      400: 'CD',
      100: 'C',
      90: 'XC',
      50: 'L',
      40: 'XL',
      10: 'X',
      9: 'IX',
      5: 'V',
      4: 'IV',
      1: 'I'
    };

    let myNumString = "";
    //Get the key values from our numConvertor. We will dual-purpose these:
    // First, they define the key for getting values of out numConvertor, and
    // second, they are the value we want to use to reduce num at each step.
    let  keys = Object.keys(numConvertor);
    
    // We don't get object keys in any order, so let's sort them.
    keys.sort((a, b) => b - a);
    console.log(keys);
    
    let i = 0;
    
    // Our loop is not a for loop, as I want to break the loop when either of two
    //  conditions are met:
    //  - Have we reached the max index?
    //  - Has num been reduced to zero?
    // In either of these cases, the loop can stop.
    while(i<keys.length && num >0){
      // Debug - what is num, the current index, the current value,
      //    and the string we're building?
      console.log(num, i, keys[i], numConvertor[keys[i]], myNumString);
      // Check if the current value of num is divisible by the current key value
      if (Math.floor(num / keys[i]) > 0){
        // If it is, how many times?
        let thisManyTimes = Math.floor(num / keys[i]);
        //  We can append that many of the current character to our string.
        myNumString += numConvertor[keys[i]].repeat(thisManyTimes);
        // And we can also reduce num. The reduction is the modulo function -- 
        //   divided by our current key value, what is the remainder?
        num = num % keys[i];
      }
      // Whether it was divisible or not, increment our index. 
      i++;
    }
    
    return myNumString;
  }
      
  console.log("2018 in roman numerals: ",convertToRoman(2018) );

              
            
!
999px

Console