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

              
                <article>
  <h2>JavaScript Arrays</h2>
  <section>
    <aside id="left">
      <p>Player</p>
      <ul id="list">

      </ul>
    </aside>
    <aside id="right">
      <p>Player Information</p>
      <ul id="playerData">

      </ul>
    </aside>
  </section>
</article>
              
            
!

CSS

              
                * {
  text-align: center;
}
section {
  border: solid 2px black;
  border-radius: 7px;
  margin: auto;
  background-color: #2d3e50;
}
article {
  width: 100%;
  text-align: center;
}
aside {
  margin: 2px;
}
p {
  border: solid 2px black;
  border-radius: 7px;
  background-color: #00bda5;
  margin: 5px;
  padding: 5px;
  color: #2d3e50;
}
#left {
  display: inline-grid;
  width: 15%;
}
#right {
  display: inline-grid;
  width: 80%;
}
ul {
  list-style: none;
  display: block;
  padding: 0px;
  margin: 0px;
}
li {
  border: solid 2px black;
  border-radius: 7px;
  text-align: left;
  color: white;
  margin: 5px;
  padding: 10px;
  background-color: #ff5c35;
}
#left li {
  text-align: center;
}

              
            
!

JS

              
                //////////////////////////////////////////////////////////////////////////
// Create player with Array constructor, Array literal, and empty array //
//////////////////////////////////////////////////////////////////////////
const first_player = new Array("Dennis", 40, "5'10");
const second_player = ["Artemis", 35, "5’5"];
const third_player = [];

//////////////////////////////////////////////////////////
// Use the item edit method to add items — should avoid //
//////////////////////////////////////////////////////////
third_player[0] = "Dee";
third_player[1] = 40;
third_player[2] = "5'10";

////////////////////////////////////////////////////////////////////////
// Add/remove item to/from end of 1st player with push and pop method //
////////////////////////////////////////////////////////////////////////
first_player.push("Actress");
first_player.pop(3);

//Edit 3rd player info item
third_player[0] = "Deandra";

////////////////////////////////
// Nest arrays then sort them //
////////////////////////////////
const total_players = [first_player, second_player, third_player];
total_players.sort();

////////////////////////////////////////////////////////
// Loop through arrays and display them on the screen //
// Note the length -1 to match the index of each item //
////////////////////////////////////////////////////////
for (i = 0; i <= total_players.length - 1; i++) {
  const player = total_players[i];

  //Create and append LI for Player Information column, then set #id attribute
  let playerInstance = document.createElement("LI");
  document.getElementById("playerData").appendChild(playerInstance);
  playerInstance.setAttribute("id", `player${i}`);

  //Create and append LI for Player column, then set #id attribute
  let playerNumber = document.createElement("LI");
  document.getElementById("list").appendChild(playerNumber);
  playerNumber.setAttribute("id", `playerNum${i + 1}`);

  //Create player number text node, then append text node
  let playerNum = document.createTextNode(`${i + 1} `);
  playerNumber.appendChild(playerNum);

  /////////////////////////////////////////////////////////////////////////
  // Set up do-while loop to handle displaing items in each player array //
  /////////////////////////////////////////////////////////////////////////
  let idx = 0;
  do {
    //Create text node for player information item and comma
    let playerInfo = document.createTextNode(`${player[idx]}`);
    playerInstance.appendChild(playerInfo);

    //Conditional comma for readability
    let comma = document.createTextNode(`, `);

    idx++;

    //After incrementer, no need for decrementer
    if (idx < player.length) playerInstance.appendChild(comma);
  } while (
    //NOTE: A do while loop does not need to decrement the length value by 1
    idx < player.length
  );
}

              
            
!
999px

Console