Pen Settings



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


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


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.


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.


                <div style="margin-bottom: 30px; height: 28px; text-align: center;">
  <script src=""></script>
  <a class="github-button" href="" data-size="large" data-show-count="true" aria-label="Follow @bookchiq on GitHub" target="_blank">Follow @bookchiq</a>
  <div class="container">
    <form action="" id="form">
      <div class="panel panel-default">
        <div class="panel-heading">
          <a href="" target="_blank">Habitica</a> - Batch create sub-tasks
        <div class="panel-body">
          <!-- api user -->
          <div class="form-group">
            <label class="control-label">
              User ID
            <input type="text" id="api-user" class="form-control">
          <!-- api token -->
          <div class="form-group">
            <label class="control-label">
              API Token
            <input type="text" id="api-token" class="form-control">
            <i class="glyphicon glyphicon-question-sign text-danger"></i>
            <a href="" class="text-warning" target="_blank">
              How to find out my User ID and API Token? - Settings / API

          <!-- task type -->
          <div class="form-group">
            <label class="control-label">Task Type</label>
              <label class="radio-inline">
                <input type="radio" name="task-type" id="inlineRadio2" value="todo" checked> To-Do
              <label class="radio-inline">
                <input type="radio" name="task-type" id="inlineRadio1" value="daily"> Daily

          <!-- task title -->
          <div class="form-group">
            <label class="control-label">Task Title</label>
            <input type="text" id="task-title" class="form-control">

          <!-- task items -->
          <div class="form-group">
            <label class="control-label">Checklist</label>
            <textarea class="form-control" id="checklist" rows="5" placeholder="first item
second item
third item
            <p class="help-inline">Sub-tasks, one item per row.</p>
        <div class="panel-footer">
          <button class="btn btn-primary">Create</button>
          <span id="message"></span>


                body {
  padding: 30px;

#message {
  margin-left: 10px;


var createTask, getTaskData, getUserData, guid, handleFormSubmit, initialize, isBlank, makeChecklist, makeItem, restoreUserData, s4, showMessage, validateTaskData;

guid = function() {
  return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();

s4 = function() {
  return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);

showMessage = function(msg, level) {
  if (msg) {
    return $('#message').html(`<span class="text-${level}">${msg}</span>`);
  } else {
    return $('#message').html('Creating...', 'info');

getUserData = function() {
  var token, user, userData;
  userData = {};
  token = _.trim($('#api-token').val());
  if (token) {
    userData['x-api-key'] = localStorage['habitica-api-token'] = token;
  } else {
    throw new Error('Api token is required');
  user = _.trim($('#api-user').val());
  if (user) {
    userData['x-api-user'] = localStorage['habitica-api-user'] = user;
  } else {
    throw new Error('User ID is required');
  return userData;

restoreUserData = function() {
  return $('#api-token').val(localStorage['habitica-api-token']);

makeItem = function(text) {
  return {
    id: guid(),
    text: text,
    completed: false

isBlank = function(text) {
  return !_.trim(text);

makeChecklist = function() {
  var text;
  text = $('#checklist').val();
  return _.chain(text).split('\n').reject(isBlank).map(makeItem).value();

getTaskData = function() {
  var task;
  return task = {
    type: $('[name=task-type]:checked').val(),
    text: _.trim($('#task-title').val()),
    checklist: makeChecklist()

validateTaskData = function(taskData) {
  if (!taskData.text) {
    throw new Error('task title is required');
  if (taskData.checklist.length === 0) {
    throw new Error('checklist is required');

resetTaskForm = function() {

createTask = function(userData, taskData) {
  return $.ajax({
    url: '',
    method: 'POST',
    headers: userData,
    data: taskData,
    success: function() {
      return showMessage('Task created successfully! Now refresh your task list.', 'success');
    error: function(xhr, status, err) {
      showMessage('Task failed to create.', 'danger');
      return console.error(err);

handleFormSubmit = function(evt) {
  var err, taskData, userData;
  try {
    userData = getUserData();
    taskData = getTaskData();
    createTask(userData, taskData);
  } catch (error) {
    err = error;
    showMessage(err.message, 'danger');
  return false;

initialize = function() {
  return $('#form').submit(handleFormSubmit);