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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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
Loading ..................

Console