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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <div class="wrapper">
      <div class="todolist">
        <h1>WEB DESIGN STUDENT TO DO LIST</h1>
        <input type="text" id="todoInput" placeholder="What do you need to do today...." />
        <div class="list">
          
          
        </div>
        <!-- /.list -->
      </div>
      <!-- /.todolist -->
    </div>
    <!-- /.wrapper -->
              
            
!

CSS

              
                $radius: 15px;
$width: 836px;
$shadow: 0px 4px 5px;

body {
  font-family: Arial, Helvetica, sans-serif;
}

#background-left {
  position: absolute;
  left: 0;
  z-index: -1;
}

#background-right {
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: -1;
}

h1 {
  text-align: center;
}
.wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  .todolist {
    input {
      text-align: center;
      width: $width;
      border-radius: $radius;
      height: 60px;
      font-size: 30px;
      margin-bottom: 2%;
      border: none;
      box-shadow: $shadow rgba(0, 0, 0, 0.25);
    }
    .list {
      padding-top: 5%;
      background: #ffffff;
      width: $width;
      height: 45vh;
      box-shadow: $shadow rgba(0, 0, 0, 0.25);
      border-radius: $radius;
      justify-content: center;
      align-items: center;
      overflow-y: auto;
      .outer-item {
        transition: opacity 1000ms linear;
        animation-name: fadeOut;
        margin-top: 2%;
        display: flex;
        align-items: center;
        justify-content: center;
        .to-do-item {
          padding-left: 2%;
          display: flex;
          align-items: center;
          background: #cac5dc;
          box-shadow: 0px 4px 5px rgba(0, 0, 0, 0.25);
          border-radius: 10px;
          height: 60px;
          width: 95%;
          justify-content: space-between;
          
          span {
            
            text-align: right;
            cursor: pointer;
            margin-right: 2%;
          }
        }
      }
    }
  }
}
              
            
!

JS

              
                //get localstorage todolist
var todoList = []

document.addEventListener("DOMContentLoaded", run);

function run() {
  let todos = localStorage.getItem('list');
  if (todos) {
    todoList = localStorage.getItem('list').split(',');
  }
  /**
   * List is defined within a function.
   * Such we cannot access it outside of the function
   * it was defined in. Therefore, we must pass
   * list to any function that needs to use it
   **/
  buildList();

  /***
   * Set up an event to listen that fires on enter being pressed
   */
  document.addEventListener("keydown", handleKeyDown);
}

function handleKeyDown(e) {
  const newTodoItem = document.querySelector("#todoInput")
  if (newTodoItem.value != "" && e.key == "Enter") {
    todoList.push(newTodoItem.value);
    localStorage.setItem('list', todoList);
    newTodoItem.value = "";
    buildList();
  }
}

function handleCloseClick(e) {
  /**
   *  What is going on here?
   *  First explore what the data set is
   *  Next, look up array.slice (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
   */
  //Look at how you would use array filter
  todoList.splice(parseInt(e.target.dataset.outerItem), 1);
  const outer_item = document.querySelector(`#outer-item-${e.target.dataset.outerItem}`);
  outer_item.style.opacity = 0;
  setTimeout(() => {
    buildList();
  }, 1000);
}

function buildList() {

  //Put list in local storage
  /**
   * Reverse the list
   */

   todoList.reverse();

  /**
   * Here we grab a reference to our list
   */

  const listHtmlElm = document.querySelector(".list");

  /**
   * Below, I use the array.map method to iterate over our todo list
   * I pass an arrow function into map https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
   * Can you work out what's going on below? Why are we using map here and forEach below
   */
  let htmlList = todoList.map((item, id) => buildListItemTemplate(item, id)).join(' ');
  listHtmlElm.innerHTML = htmlList;



  /**
   * Below, I use the query selector to grab all of the close span tags by class and add a click
   * event listener
   */

  document
    .querySelectorAll(".close")
    .forEach(e => e.addEventListener("click", handleCloseClick));
}

function buildListItemTemplate(listItem, id) {
  /**
   * observe how we are using a new javaScript
   * feature here, template literals (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals).
   * Template literals are incredibly useful and allow us to easily embed
   * vars in a string
   **/

  var btn = document.createElement("BUTTON");

  return `<div class="outer-item" id="outer-item-${id}" >
    <div class="to-do-item">
      <p> ${listItem} </p>
      <span class="close" data-outer-item="${id}" >  X </span>
    </div>
    <!-- /.to-do-item -->
  </div>
  <!-- /.outer-item -->`
}
              
            
!
999px

Console