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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

              
                <body class="bg-dark text-white">
  <div class="container-fluid m-0 p-0" id="content">

    <div class="row w-100">
    <div class="col-12 text-center">
      <h1 class="text-center pt-2">Top Qualities of a JS Programmer</h1></div></div>
    <div class="row w-100">
    <div class="col-12 text-center">
    <h2>List Items: </h2>
      </div>
     <div class="col-12 text-center">
       <img src="https://images.pexels.com/photos/2194062/pexels-photo-2194062.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" id="programmingImage" alt="Javascript Code">
      </div>
      
    </div>
    <div class="row w-100 justify-content-center">
    <div class="col-3 text-center">
      <h1 id="header">List</h1>
      <h2>Qualities</h2>
      <span id="highlight-confirm"></span>
    </div> 
    </div>
    
    <div class="row justify-content-center w-100">
    <div class="col-2 ">
      <ul id="myList">
        <li id="one">Passionate</li>
        <li id="two">Flexible</li>
        <li id="three">Deep Knowledge</li>
        <li id="four">Communication Skills</li>
        <li id="five">Team Player</li></ul>
    </div>
    </div>
    
    <div class="row w-100 justify-content-center">
    <div class="col-3 pl-5">
      <button onclick="addEnd()">Add Item</button>
      <button onclick="randomize()">Random!</button>
      <button onclick="remove()">Remove...</button>
    </div>
    </div>
    
    </div>
  </div>

  
</body>
              
            
!

CSS

              
                body {

}
#programmingImage {
  height: 200px;
  width: auto;
  border-radius: 25px;
}

.highlight-li {
  background-color: yellow;
  color: black;
}
              
            
!

JS

              
                // ADDING ITEMS TO START AND END OF LIST
var list = document.getElementsByTagName('ul')[0];                 // Get the <ul> element

var listItems = document.querySelectorAll('li');                   // All <li> elements

// ADD NUMBER OF ITEMS IN THE LIST TO THE HEADING
var heading = document.querySelector('h2');                        // h2 element
var headingText = heading.firstChild.nodeValue;                    // h2 text
var totalItems = listItems.length;                                 // No. of <li> elements
var newHeading =  headingText + '<span>' + totalItems + '</span>'; // Content
heading.innerHTML = newHeading;                                    // Update h2 using innerHTML (not textContent) because it contains markup


function addEnd()
{
  // ADD NEW ITEM TO END OF LIST
  var newItemLast = document.createElement('li');                    // Create element
  var newTextLast = document.createTextNode(prompt("What would you like to add to the list?"));                // Create text node
  newItemLast.appendChild(newTextLast);                              // Add text node to element
  list.appendChild(newItemLast);   
  var div = document.getElementById("content");
  div.innerHTML += "<div class=\"row w-100 pt-3 justify-content-center\"><div class=\"col-6 text-center\">Item added!</div></div>";
  listItems = document.querySelectorAll('li'); 
}

function randomize() {
  var i;                                                             // Counter variable
  for (i = 0; i < listItems.length; i++) {                           // Loop through elements
  listItems[i].className = '';                                 // Change class to cool
  }
  
  var highlight = [];
  
  highlight[0] = Math.floor(Math.random() * Math.floor(listItems.length));
  
  do {
    highlight[1] = Math.floor(Math.random() * Math.floor(listItems.length));
  }while(highlight[0] == highlight[1]);
  
  do {
    highlight[2] = Math.floor(Math.random() * Math.floor(listItems.length));
  }while(highlight[0] == highlight[2] || highlight[1] == highlight[2]);
  
  
  listItems[highlight[0]].className = 'highlight-li'; 
  listItems[highlight[1]].className = 'highlight-li'; 
  listItems[highlight[2]].className = 'highlight-li'; 
  
  var div = document.getElementById("highlight-confirm");
  div.innerHTML = "<p>The top qualities are highlighted below.</p>";
  
}

function remove() {
  
  
listItems[Math.floor(Math.random() * Math.floor(listItems.length))].innerHTML = '';
    
  
  var div = document.getElementById("content");
  div.innerHTML += "<div class=\"row w-100 pt-3 justify-content-center\"><div class=\"col-6 text-center\">Item removed!</div></div>";
  listItems = document.querySelectorAll('li');
}
              
            
!
999px

Console