css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <p class="note">This CodePen is copy/pasted compiled code for demo purposes - see the real repo <a href="https://github.com/laras126/myers-briggs">on Github</a>.</p>

<section id="js-app" class="app">

  <header class="app-header">
    <h1 class="app-title">Myers Briggs for Web People</h1>
    <p class="app-tagline">a.k.a. The Unicorn Test</p>
  </header>

  <div class="question">
    <p class="question-text" id="js-question"></p>
    <p class="caption question-type" id="js-question-type"></p>
  </div>

  <div class="answers-container">
    <ul class="answers-list" id="js-answers">
      <li class="answer" data-score="0">0 <span class="caption answer-caption -first">Don't know/Disagree</span></li>
      <li class="answer" data-score="1">1</li>
      <li class="answer" data-score="2">2</li>
      <li class="answer" data-score="3">3</li>
      <li class="answer" data-score="4">4 <span class="caption answer-caption -last">Know well/Strongly agree</span></li>
    </ul>
  </div>

  <div class="bar-container" id="js-bar-container">
    <div class="bar" id="bar-template">
      <div class="bar-title caption"></div>
      <span class="bar-value"></span>
    </div>
  </div>

</section>

            
          
!
            
              // This is compiled code!

.note {
  text-align: center;
  background: lemonchiffon;
  margin: 0;
  padding: 0.8rem;
  font-size: 0.8rem;
}

.note a {
  font-weight: bold;
  color: indianred;
}

.caption {
  position: absolute;
  top: -1rem;
  font-size: 0.75rem;
}

.answers-container {
  width: 90%;
  max-width: 20rem;
  margin: 2rem auto;
}
.answers-list {
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  width: 100%;
  position: relative;
  padding-left: 0;
}
.answer {
  cursor: pointer;
  padding: 1rem 2rem;
  margin-bottom: 0.2rem;
  background-color: paleturquoise;
  list-style-type: none;
  border: 1px solid paleturquoise;
}
.answer:hover {
  border-color: lightslategray;
  background-color: lemonchiffon;
}
.answer-caption.-first {
  left: -3rem;
}
.answer-caption.-last {
  right: -1.4rem;
}
#bar-template {
  display: none;
}
.bar-container {
  padding-top: 1rem;
  width: 80%;
  margin: auto;
}
.bar {
  margin-top: 2rem;
  text-align: left;
  position: relative;
  background-color: #EEE;
  height: 2rem;
}
.bar-title {
  display: inline-block;
}
.bar-value {
  height: 100%;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  -webkit-box-pack: end;
      -ms-flex-pack: end;
          justify-content: flex-end;
  width: 15px;
  padding-right: 3px;
}
#backValue {
  background-color: lightslategray;
}
#designValue {
  background-color: peachpuff;
}
#jsValue {
  background-color: lightblue;
}
#frontValue {
  background-color: lemonchiffon;
}
/* * {
  box-sizing: border-box;
  color: var(--color-blue);
} */
body {
  color: #444;
  font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
}
.app {
  text-align: center;
  max-width: 720px;
  margin: auto;
  padding-bottom: 2rem;
}
.app-header {
  padding-top: 1rem;
  padding-bottom: 1rem;
}
.app-title {
  font-size: 2rem;
  margin-bottom: 0;
}
.app-tagline {
  font-style: italic;
  border-bottom: 1px solid #EEE;
  padding-bottom: 1rem;
}
.question {
  position: relative;
}
.question-text {
  font-size: 1.2rem;
  padding-bottom: 1rem;
  padding-top: 1rem;
}
.question-type {
  text-align: center;
  width: 100%;
  color: #AAA;
}


            
          
!
            
              // Compiled code!!

/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// identity function for calling harmony imports with the correct context
/******/ 	__webpack_require__.i = function(value) { return value; };
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, {
/******/ 				configurable: false,
/******/ 				enumerable: true,
/******/ 				get: getter
/******/ 			});
/******/ 		}
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 3);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {

// removed by extract-text-webpack-plugin

/***/ }),
/* 1 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
/* harmony export (immutable) */ __webpack_exports__["a"] = createScoresObject;
function createScoresObject(ques) {
  let Scores = {};

  ques.forEach( qdata => {
    if( !Scores.hasOwnProperty(qdata.type) ) {
      Scores[qdata.type] = 0;

      // Add to UI
      let div = document.getElementById('bar-template'),
          clone = div.cloneNode(true);

      clone.removeAttribute('id');
      clone.children[0].innerHTML = qdata.type;
      clone.children[1].innerHTML = Scores[qdata.type];
      clone.children[1].id = qdata.type + 'Value';

      document.querySelector('#js-bar-container').appendChild(clone);

    }
  });

  return Scores;
}


/***/ }),
/* 2 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return questions; });

// Static questions data

let questions = [
  {
    text: 'I can shard a database.',
    type: 'back',
  },
  {
    text: 'I know design tools like Sketch, Adobe Illustrator, or Photoshop well.',
    type: 'design',
  },
  {
    text: 'I can write a regex.',
    type: 'back',
  },
  {
    text: 'I know the difference between == and ===.',
    type: 'js',
  },
  {
    text: 'I know when to use call() vs. apply().',
    type: 'js',
  },
  {
    text: 'I understand how the browser paints a webpage.',
    type: 'back',
  },
  {
    text: 'I am comfortable recommending server-side caching techniques.',
    type: 'back',
  },
  {
    text: 'I enjoy designing page layouts.',
    type: 'design',
  },
  {
    text: 'I enjoy architecting a stylesheet.',
    type: 'front',
  },
  {
    text: 'I am greatly inspired by the work of Paula Scher, Dieter Rams, and Stefan Sagmeister.',
    type: 'design',
  },
  {
    text: 'I am greatly inspired by publications like CSS-Tricks, A List Apart, and Smashing Magazine.',
    type: 'front',
  },
  {
    text: 'Bad kerning bothers me.',
    type: 'design',
  },
  {
    text: 'I know the difference between the Quick Sort and Merge Sort algorithms.',
    type: 'back',
  },
  {
    text: 'I am comfortable referring to a stack trace when debugging my code.',
    type: 'back',
  },
  {
    text: 'I gain meaningful information from CSS-Tricks.',
    type: 'front',
  },
  {
    text: 'I can style a satisfying-to-click button.',
    type: 'front',
  },
  {
    text: 'This bothers me: &lt;IMG SRC=\"\">.',
    type: 'front',
  },
  {
    text: 'I enjoy debugging CSS.',
    type: 'front',
  },
  {
    text: 'I know how to identify garbage collection using dev tools.',
    type: 'js',
  },
];


/***/ }),
/* 3 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__css_app_css__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__css_app_css___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__css_app_css__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__questions_js__ = __webpack_require__(2);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__Scores_js__ = __webpack_require__(1);






// Questions array import
const questions = __WEBPACK_IMPORTED_MODULE_1__questions_js__["a" /* questions */],
      Scores = __WEBPACK_IMPORTED_MODULE_2__Scores_js__["a" /* createScoresObject */](questions);

// App object
const App = {

  el: {
    question: document.getElementById('js-question'),
    questionType: document.getElementById('js-question-type'),
  },

  data: {
    qIndex: 0,
  },

  setQuestionText() {
    this.el.question.innerHTML = questions[this.data.qIndex].text
    this.el.questionType.innerHTML = questions[this.data.qIndex].type;

  },

  isLastQuestion() {
    if( this.data.qIndex == questions.length - 1 ) {
      return true;
    } else {
      return false;
    }
  },

  hasMoreQuestions() {
    if( this.data.qIndex <= questions.length ) {
      return true;
    } else if( this.data.qIndex == questions.length ) {
      return false;
    }
  },

  updateBarWidth(el, val) {

    let width = el.offsetWidth,
        oldWidth = parseInt(width, 10),
        newWidth = oldWidth + val*10 + 'px';
    if( val !== 0 ) {
      el.style.width = newWidth;
    }
  },

  updateQuestion() {

    this.data.qIndex++;

    if ( this.isLastQuestion() ) {
      this.el.question.innerHTML = "No more questions.";
      document.querySelector('.answers-list').innerHTML = "Done!";
    } else {
      this.setQuestionText();
    }

  },

  init() {
    this.setQuestionText();
  }
}

App.init();


// Use event delegation to handle the click event
document.getElementById('js-answers').addEventListener('click', function(e) {

  App.updateQuestion();

  if(e.target && e.target.nodeName === 'LI') {

    let currentQuestion = questions[App.data.qIndex - 1],
        targetScore = currentQuestion.type,
        clickVal = +e.target.dataset.score,
        targetEl = document.getElementById(targetScore + 'Value');

    // Update scores
    Scores[targetScore] += clickVal;
    targetEl.innerHTML = Scores[targetScore];

    App.updateBarWidth(targetEl, clickVal);

    console.log(Scores);
  }

});


/***/ })
/******/ ]);
            
          
!
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