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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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.

            
              <!-- questions taken from http://davidshariff.com/quiz/ -->
<header>
  <small>Multiple Choice Quiz w/ jQuery</small>
</header>
<div id="emc-score"></div>
<div class="wrap">
  <div class="row">
  <section data-quiz-item>
    <div class="question">Are CSS property names case-sensitive?<br>Ex: <code>baCkgRouNd: #333;</code></div>
    <div class="choices" data-choices='["Yes","No"]'>
    </div>
  </section>
  <section data-quiz-item>
    <div class="question">Does setting <code>margin-top:</code> and <code>margin-bottom:</code> have an affect on an inline element?</div>
    <div class="choices" data-choices='["Yes","No"]'>
    </div>
  </section>
  </div>
  <div class="row">
  <section data-quiz-item>
    <div class="question">The <code>translate()</code> function can move the position of an element on the z-axis.</div>
    <div class="choices" data-choices='["True","False"]'>
    </div>
  </section>
   <section data-quiz-item>
     <div class="question">The pseudo class <code>:checked</code> will select inputs with type radio or checkbox, but not option elements.</div>
    <div class="choices" data-choices='["True","False"]'>
    </div>
  </section>
  </div>
   <div class="row">
  <section data-quiz-item>
    <div class="question">Does setting <code>padding-top:</code> and <code>padding-bottom:</code> on an inline element add to its dimensions?</div>
    <div class="choices" data-choices='["Yes","No"]'>
    </div>
  </section>
   <section data-quiz-item>
     <div class="question">If you have a <code>p</code> element with <code>font-size: 10rem;</code>, will the text be responsive when the user resizes / drags the browser window?</div>
    <div class="choices" data-choices='["Yes","No"]'>
    </div>
  </section>
  </div>
   <div class="row last">
  <section data-quiz-item>
    <div class="question">In a HTML document, the pseudo class <code>:root</code> always refers to the html element.</div>
    <div class="choices" data-choices='["True","False"]'>
    </div>
  </section>
   <section data-quiz-item>
    <div class="question">The formula context/target = result is useful when building responsive layouts.</div>
    <div class="choices" data-choices='["True","False"]'>
    </div>
  </section>
  </div>
  <div class="submit">
  <button id="emc-submit">Submit Answers</button>
  </div>
</div>

<footer>
<div id="emc-progress"></div>
</footer>
<div class="attrib">
  <p>Take the full quiz <i class="fa fa-long-arrow-right"></i> <a href="http://davidshariff.com/quiz/" target="_blank">http://davidshariff.com/quiz/</a></p>
</div>
            
          
!
            
              @import "bourbon";

@import url('//fonts.googleapis.com/css?family=Raleway:400,800');
@import url('//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css');

%clearfix {
  &:after {clear:both;content:"";display:table;}
  &:before { content:"";display:table;} }

$green: #2dceb1;
$red: #ff383e;
$wht: #fbfbfb;
$grey: #fdfdfd;
$type: #737373;

$cancel: "\f00d";
$check: "\f00c";

@mixin chk($color,$content) {
	&:before {
      position: absolute;
      z-index: 399;
      bottom: 0;
      right: 0;
      content: "";
      height: 0;
      width: 0;
      border: 35px solid;
      border-color: transparent lighten($color,7%) lighten($color,7%) transparent;
    }
    &:after {
      line-height: 1.4;
      position: absolute;
      z-index: 499;
      font-family: 'fontawesome';
      content: $content;
      bottom: 0;
      right: 7px;
      font-size: 1.9em;
      color: $color;
    }
}

*,*:after,*:before{@include box-sizing(border-box);}
body {
  background: #fff;
  font-family: 'Raleway';
  line-height:1.55;
  color: $type;
  font-weight: 400;
  a {
    color:darken($green,7%);
    text-decoration: none;
    border-bottom: 2px solid #fff;
    &:hover {
     border-color: darken($wht,5%);
    }
  }
}
code {
  background: #fff;
  color: lighten($type,15%);
  padding: 2px 8px;
}
header {
  position: relative;
  text-align: center;
  text-transform: uppercase;
  color: darken($green,15%);
  border-bottom: 1px solid dareken($green,15%);
  letter-spacing: 4px;
  padding: 12px 0;
  background: darken($wht,.5%);
  border-bottom: 1px solid darken($wht,5%);
}
.wrap {
  max-width: 48em;
  margin:  0 auto;
  padding: 2.5em 0 4em;
}
.row {
   @extend %clearfix;
  &.last {
      border-bottom: 1px solid darken($wht,5%);
  }
}
section {
  position: relative;
  padding: 30px 20px;
  width: 50%;
  min-height: 12em;
  float: left;
  background: darken($wht,.5%);
  border-top: 1px solid darken($wht,5%);
  border-left: 1px solid darken($wht,5%);
  &:nth-child(even) {
    border-right: 1px solid darken($wht,5%);
  }
  &.item-incorrect {
   background: darken($wht,2%);
   @include chk($red,$cancel);
  }
  &.item-correct {
   @include chk($green,$check);
  }
}

input[type="radio"] {
  position: absolute;
  visibility: hidden;
  + label {
    background: #fff;
    display: inline-block;
    padding: 5px 15px;
    margin: 5px 10px 5px 0;
    border: 1px solid darken($wht,5%);
    @include transition(all .1s linear);
    
    &:before {
      content:"\f10c";
      font-family: 'fontawesome';
      margin-right: 7px;
      color: $green;
    }
    &:hover {
      cursor: pointer;
  }
  }
  &:checked + label {
    background: lighten($green,9%);
    color: darken($green,15%);
    &:before {
      content:"\f192";
      color: darken($green,15%);
    }
  }
}

.question {
  font-weight: bold;
}
.submit {
  padding: 20px 5px;
  button {
    display: block;
    outline: none;
    width: 300px;
    margin: 1em auto 1.5em;
    padding: .8em 1em;
    background: darken($wht,1%);
    color: darken($wht,12%);
    text-transform: uppercase;
    letter-spacing: 3px;
    border: 1px solid darken($wht,5%);
  }
}
#emc-score {
  text-align: center;
  opacity: 0;
  padding: 0;
  @include transition(all .55s ease);
  &.new-score {
    opacity: 1;
    background: $green;
    color: $wht;
    padding: 20px;
  }
}
#emc-submit {
  position: relative;
  @include transition(all .33s ease);
  &.ready-show {
     background: $green;
     color: darken($green,15%);
     border: none;
     border-bottom: 2px solid darken($green,7.5%);
     box-shadow: 0 1px 1px rgba(#444,.2);
     @include transform(rotateX(360deg));
    &:hover {
      color: $wht;
      background: darken($green,7%);
      border-color: darken($green,15%);
    }
    &:active {
      top: 2px;
      border-bottom: none;
    }
  }
}
#emc-progress {
  height: 100%;
  border: 1px solid darken($green,15%);
  background: $green;
}
#emc-progress_inner {
  width: 100%;
  height: 0;
  background: darken($green,15%);
  @include transition(height .33s $ease-in-out-back);
}
#emc-progress_ind {
  position: absolute;
  display: block;
  width: 100%;
  font-size: .7em;
  font-weight: bold;
  padding: 7px 5px 5px;
  top: 0;
  left: 0;
  text-align: center;
  color: darken($green,15%);
}

footer {
  position: fixed;
  width: 40px;
  height: 100%;
  background: rgba($wht,.85);
  bottom: 0;
  left: 0;
  padding: 25px 12px 10px;
}
.attrib {
  padding: 10px 0;
  text-align: center;
  i {
    margin-right: 7px;
    margin-left: 7px;
  }
}
            
          
!
            
              (function($) {
  $.fn.emc = function(options) {
    
    var defaults = {
      key: [],
      scoring: "normal",
      progress: true
    },
    settings = $.extend(defaults,options),
    $quizItems = $('[data-quiz-item]'),
    $choices = $('[data-choices]'),
    itemCount = $quizItems.length,
    chosen = [],
    $option = null,
    $label = null;
    
   emcInit();
    
   if (settings.progress) {
      var $bar = $('#emc-progress'),
          $inner = $('<div id="emc-progress_inner"></div>'),
          $perc = $('<span id="emc-progress_ind">0/'+itemCount+'</span>');
      $bar.append($inner).prepend($perc);
    }
    
    function emcInit() {
      $quizItems.each( function(index,value) {
      var $this = $(this),
          $choiceEl = $this.find('.choices'),
          choices = $choiceEl.data('choices');
        for (var i = 0; i < choices.length; i++) {
          $option = $('<input name="'+index+'" id="'+index+'_'+i+'" type="radio">');
          $label = $('<label for="'+index+'_'+i+'">'+choices[i]+'</label>');
          $choiceEl.append($option).append($label);
        	
          $option.on( 'change', function() {
            return getChosen();
          }); 
        }
      });
    }
    
    function getChosen() {
      chosen = [];
      $choices.each( function() {
        var $inputs = $(this).find('input[type="radio"]');
        $inputs.each( function(index,value) {
          if($(this).is(':checked')) {
            chosen.push(index + 1);
          }
        });
      });
      getProgress();
    }
    
    function getProgress() {
      var prog = (chosen.length / itemCount) * 100 + "%",
          $submit = $('#emc-submit');
      if (settings.progress) {
        $perc.text(chosen.length+'/'+itemCount);  
        $inner.css({height: prog});
      }
      if (chosen.length === itemCount) {
        $submit.addClass('ready-show');
        $submit.click( function(){
          return scoreNormal();
        });
      }
    }
    
    function scoreNormal() {
      var wrong = [],
          score = null,
          $scoreEl = $('#emc-score');
      for (var i = 0; i < itemCount; i++) {
        if (chosen[i] != settings.key[i]) {
          wrong.push(i);
        }
      }
      $quizItems.each( function(index) {
        var $this = $(this);
        if ($.inArray(index, wrong) !== -1 ) {
        	$this.removeClass('item-correct').addClass('item-incorrect');
        } else {
          $this.removeClass('item-incorrect').addClass('item-correct');
        }
      });
      
      score = ((itemCount - wrong.length) / itemCount).toFixed(2) * 100 + "%";
      $scoreEl.text("You scored a "+score).addClass('new-score');
      $('html,body').animate({scrollTop: 0}, 50);
    }
 
  }
}(jQuery));


$(document).emc({
  key: ["2","1","2","2","2","2","1", "1"]
});
            
          
!
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