cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <div class="quests">
  <h1>Quest Log<span id="total"></span></h1>
  <input id="quest_input" type="text" placeholder="What is your quest?" autocomplete="off">
  <button id="add" class="btn green">Add<span class="tooltip">Add new quests to your Quest Log</span></button>
  <button id="turn_in" class="btn blue">Turn In Quests<span class="tooltip">Turn in completed quests for xp</span></button>
  <hr>
  <ul id="quest_list"></ul>
</div>
            
          
!
            
              * {
  box-sizing: border-box;
}

body {
  background-color: #252525;
  color: #ccc;
}

h1 {
  margin-bottom: 15px;
}

hr {
  border: 1px solid #303030;
  width: 94%;
  margin-left: 0;
}

.quests {
  width: 500px;
  height: 500px;
  text-align: left;
  margin: 0 auto;
  padding: 35px 15px;
}

.btn {
  position: relative;
  display: inline-block;
  height: 30px;
  font-size: .75em;
  color: #fff;
  text-transform: lowercase;
  border-style: none;
  border-radius: 3px;
  padding: 0 20px;
  margin-left: 5px;
}

.btn .tooltip {
  visibility: hidden;
  position: absolute;
  bottom: 140%;
  left: 50%;
  width: 140px;
  background-color: #303030;
  color: #fff;
  font-size: 12px;
  text-transform: none;
  border: 1px solid #FFBB00;
  padding: 5px 10px;
  margin-left: -70px;
  z-index: 1;
}

.btn .tooltip:after {
  content: ' ';
  position: absolute;
  top: 100%;
  left: 50%;
  border-width: 7px;
  border-style: solid;
  border-color: #FFBB00 transparent transparent transparent;
  margin-left: -7px;
}

.btn:hover .tooltip {
  visibility: visible;
}

.btn:focus {
  outline: none;
}

.green {
  background-color: #70AD5F;
}

.green:hover {
  background-color: #649656;
}

.red {
  background-color: #D64836;
}

.red:hover {
  background-color: #C24332;
}

.blue {
  background-color: #30A7FC;
}

.blue:hover {
  background-color: #2B8BCF;
}

#quest_input {
  height: 35px;
  outline: none;
  padding: 10px;
  margin-left: 0;
  margin-bottom: 10px;
}

#quest_list {
  list-style: none;
  margin-left: 0;
  padding-left: 0;
}

#quest_list li {
  float: left;
  width: 94%;
  list-style: none;
  background-color: #303030;
  border-radius: 3px;
  padding: 0 10px;
  line-height: 2.5em;
  margin: 0 0 5px 0;
}

#quest_list li:hover {
  background-color: #404040;
  cursor: pointer;
}

.complete {
  color: #888;
  text-decoration: line-through;
}

.xp {
  float: right;
  color: #FFBB00;
  text-align: right;
}

.x {
  position: relative;
  float: left;
  width: 6%;
  color: #707070;
  font-weight: bold;
  font-size: 1.5em;
  background-color: transparent;
  border-style: none;
  line-height: 1.75em;
  text-align: right;
}

.x .remove_tooltip {
  visibility: hidden;
  position: absolute;
  top: 9px;
  left: 140%;
  background-color: transparent;
  color: #fff;
  font-size: 12px;
  line-height: normal;
  font-weight: normal;
  text-transform: none;
  text-align: center;
  white-space: nowrap;
  border: 1px solid #FFBB00;
  padding: 5px 10px;
  z-index: 1;
}

.x:hover .remove_tooltip {
  visibility: visible;
}

.x:hover {
  color: #D62424;
  cursor: pointer;
}

.x:focus {
  outline: 0;
}

#total {
  color: #FFBB00;
  font-size: 0.66em;
  margin-left: 25px;
}
            
          
!
            
              var questsArr = [];
var total_xp = 0;

// Pull quests from array and display
function displayQuests() {
  var ul = document.getElementById('quest_list');
  var html = '';
  // Assign ID to list item and display quest
  for (i = 0; i < questsArr.length; i++) {
    questsArr[i].id = i;
    html += '<li id ="li' + i + '" class="incomplete">' + questsArr[i].quest + '<span class="xp">' + questsArr[i].xp + 'xp</span>' + '</li><button id="x' + questsArr[i].id + '" class="x">x<span class="remove_tooltip">Delete Quest</span></button>';
  }

  ul.innerHTML = html;
  // Create delete buttons for each quest
  for (i = 0; i < questsArr.length; i++) {
    var remove = document.getElementById('x' + i);
    remove.addEventListener('click', removeQuest, i);
  }
  // Create complete button for each quest
  for (i = 0; i < questsArr.length; i++) {
    var li = document.getElementById('li' + i);
    li.addEventListener('click', completeQuest, i);
  }
}

function Quest(quest, xp, complete) {
  this.id = '';
  this.quest = quest;
  this.xp = xp;
  this.complete = false;
  questsArr.push(this);
}

// Check if quest is longer than 3 characters and then add a random xp value
function addQuest() {
  var quest = document.getElementById('quest_input').value;

  if (quest.length > 3) {
    var xp = Math.floor(Math.random() * 500 + 1);
    var complete = false;

    var newQuest = new Quest(quest, xp, complete);
    document.getElementById('quest_input').value = '';

    displayQuests();
  }
}

// Get ID of delete button and remove that quest
function removeQuest() {
  var id = this.getAttribute('id').slice(1);
  questsArr.splice(id, 1);

  displayQuests();
}

// Restyle quests to have strikethrough
function completeQuest() {

  var position = this.getAttribute('id').slice(2);

  if (this.className === 'incomplete') {
    this.className = 'complete';
    questsArr[position].complete = true;
  } else {
    this.className = 'incomplete';
    questsArr[position].complete = false;
  }
}

// Turn in quests, add xp value to total, and remove from quest array
function turnInQuests() {
  html = '';
  for (i = 0; i < questsArr.length; i++) {
    if (questsArr[i].complete) {
      total_xp += questsArr[i].xp;
      delete questsArr[i];
      html = total_xp.toLocaleString() + 'xp';
      xpSpan.innerHTML = html;
    }
  }
  questsArr = questsArr.filter(function(n) {
    return n != undefined
  });
  displayQuests();
}

var add = document.getElementById('add');
var turnIn = document.getElementById('turn_in');
var xpSpan = document.getElementById('total');

// All pressing 'ENTER' to add quest
add.addEventListener('click', addQuest);
document.getElementById('quest_input').addEventListener('keypress', function(event) {
  var key = event.which;
  if (key === 13) {
    addQuest();
  }
});
turnIn.addEventListener('click', turnInQuests);
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console