Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <p>Practice removing Array elements using <span class="keyword">splice( <span class="start">start</span>, <span class="deleteCount">deleteCount</span> )</span>:</p>

<div id="ace"></div>

<div id="type"></div>

<!-- Add support for negative values: -1 [ ADDED ]-->
<!-- Add support for list.length -->
              
            
!

CSS

              
                p {
  padding: 10px 20px;
  color: #bbb;
  font-size: 18px;
  font-family: Arial;
}
.keyword {
  font-weight: 600;
  color: #eee;
}
.start { color: green; }
.deleteCount { color: orange; }
body {
  background-color: black;
  margin: 0;
  padding: 0;
}
#ace {
  position: absolute;
  display: block;
  width: 100%;
  height: 15%;
}
#type {
  bottom:45%;
  position: absolute;
  display: block;
  width: 100%;
  height: 20%;
}
.ace_string {
  padding: 4px 6px;
  color: yellow !important;
  transition: all 500ms ease;
}
.ace_text-layer .ace_string.start {
  border-bottom: 5px solid green;
}
.ace_text-layer .ace_string.selected {
  background-color: orange;
  color:black !important;
}
.ace_text-layer .ace_string.count {
  background-color: hotpink;
  background-color: orange;
  color:black !important;
}
.myMarker {
  position:absolute;
  background: rgba(100,100,100,0.5) !important;
  z-index: 20;
}
.ace_line .ace_constant.ace_numeric:nth-child(5) {
  color: green !important;
}
.ace_line .ace_constant.ace_numeric:nth-child(7) {
  color: orange !important;
}
              
            
!

JS

              
                let params = [];
let list = [ "item 1", "item 2", "item 3", "item 4" ];
let editor = ace.edit("ace");
editor.setBehavioursEnabled(true); 				
editor.setTheme("ace/theme/monokai");   editor.getSession().setMode("ace/mode/javascript");
editor.setShowPrintMargin(false);				
editor.$blockScrolling = Infinity;
editor.setValue('\nlet list = [ "item 1", "item 2", "item 3", "item 4"];', 1);
editor.setOptions({ fontSize: "12pt" });

let type = ace.edit("type");
type.setBehavioursEnabled(true); 				
type.setTheme("ace/theme/monokai");           
type.getSession().setMode("ace/mode/javascript");
type.setShowPrintMargin(false);				
type.$blockScrolling = Infinity;
type.setValue('// Syntax: splice( start, deleteCount ); \n// Practice by typing below and pressing Enter (only numbers are allowed):\nlist.splice( _, _ );', 1);
type.setOptions({ fontSize: "12pt" });
type.getSession().on('change', function(){ update() });
type.commands.addCommand({
  name    : "Return",
  exec    : function(){
    // Remove Elements
    list.splice( params[0], params[1] );
    console.log(params, list);
    editor.setValue('\nlet list = ' + JSON.stringify(list) + ';', 1);
  },
  bindKey : { mac: "enter", win: "enter" }
});

function update(){

  let val = type.getSession().getValue();
  let args = val.match(/\(\s?(-?\d)\s?,\s?(\d)\s?\)/);
  let items = document.querySelectorAll('.ace_string');
  let start = val.match(/\(\s?(-?\d)\s?,\s?.?\s?\)/);
  Array.from(items).map((item)=>item.classList.remove('start'));
  if ( start ){
    let idx = start[1] < 0 ? items.length + parseInt(start[1]) : start[1];
    if ( idx >= 0 ){
      items[idx] && items[idx].classList.add("start");
    }
  }
  if ( args ){
    params = [ args[1], args[2] ];
    let start = parseInt(args[1]);
    let idx = start < 0 ? items.length + parseInt(start) : start;
    let abs = idx;
    let deleteCount = parseInt(args[2]);
    if ( deleteCount > 0 ){
      items[idx].classList.add("selected");
    }
    while( deleteCount > 0 ){
  
      if ( idx == abs ){
        if ( items[idx] ){
          items[idx].classList.add("selected");
          idx++;
        }
      } else {
        if ( items[idx] ){
          items[idx].classList.add("count");
          idx++;
        }
      }
      deleteCount--;
    }
  } else {
    Array.from(items).map((item)=>{
      item.classList.remove('selected');
      item.classList.remove('count');
    });
  }
}
              
            
!
999px

Console