123

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.

            
              <div id="app" class="app">
  <section class="quiz" id="quiz">
    <div v-if="!isIdle" class="progress">{{currentIndex+1}} / {{total}}
    </div>
    <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/74321/darts.svg" width="120" alt=""/>
    <h1>Well-aimed?</h1>
    <transition name="fade" mode="out-in">  
      <div v-if="isIdle" key="s1">
        <p>Your task is to decide whether a given selector targets <strong>all and only</strong> the elements marked on the right.</p>
        <button type="button" @click="start">Let's Start</button>
      </div>
      <question v-else :key="currentIndex" :v="v" :q="proposal" @answered="go" :disabled="disabled" :correct="answer"></question>
    </transition>
    <transition name="fade">
      <button v-show="shouldShowNext" type="button" @click="displayNext">Next</button>
    </transition>
    <transition name="fade">
      <button v-show="allDone" type="button" @click="showResults">Results</button>
    </transition>
  </section>
  <v-style v-if="!isIdle">.page-doc {{selector}} {
    border: 3px solid ;}  
  </v-style>
  <v-style v-if="!isIdle && disabled">.page-doc {{proposal}} {
    box-shadow: inset 0 0 0 3px #ff7058;}
  </v-style>
  <pagedoc></pagedoc>
  <transition name="fade2">
    <section class="score" v-if="askedForResults">
      <h1>Your Result is</h1>
      <finalresults :finalpercentage="finalPercentage"></finalresults>
      <button type="button" @click="playAgain">Play Again</button>
    </section>
  </transition>
</div>

<script type="text/x-template" id="finalresults">
  <svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 40" width="300px">
    <title>Results Board</title>
    <path fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="2px" class="cls-1" d="M15.93,13H2V38.5H49V13H35.07" transform="translate(-0.5 0)"/><path fill="#fff" class="cls-2" d="M21,6.65a.15.15,0,0,0-.12-.11l-2.21-.3-1-2.16a.16.16,0,0,0-.28,0l-1,2.16-2.21.3a.16.16,0,0,0-.12.11.15.15,0,0,0,0,.16L15.66,8.5l-.44,2.31a.17.17,0,0,0,.06.16.15.15,0,0,0,.16,0L17.5,9.9,19.56,11l.07,0a.14.14,0,0,0,.09,0,.17.17,0,0,0,.06-.16L19.34,8.5,21,6.81A.15.15,0,0,0,21,6.65Zm16,0a.15.15,0,0,0-.12-.11l-2.21-.3-1-2.16a.16.16,0,0,0-.28,0l-1,2.16-2.21.3a.16.16,0,0,0-.12.11.15.15,0,0,0,0,.16L31.66,8.5l-.44,2.31a.17.17,0,0,0,.06.16.15.15,0,0,0,.16,0L33.5,9.9,35.56,11l.07,0a.14.14,0,0,0,.09,0,.17.17,0,0,0,.06-.16L35.34,8.5,37,6.81A.15.15,0,0,0,37,6.65ZM30,3.41a.19.19,0,0,0-.16-.14L27,2.88,25.68.1a.21.21,0,0,0-.36,0L24,2.88l-2.83.39a.19.19,0,0,0-.16.14.21.21,0,0,0,0,.21l2.08,2.17-.57,3a.21.21,0,0,0,.07.21.2.2,0,0,0,.21,0L25.5,7.59,28.15,9l.09,0a.19.19,0,0,0,.12,0,.21.21,0,0,0,.07-.21l-.56-3,2.07-2.17A.21.21,0,0,0,30,3.41Z" transform="translate(-0.5 0)"/>
    <text style="font-size:12px" x="12.5" y="30" fill="#fff" textLength="25" lengthAdjust="spacing" small>{{finalpercentage}}</text>  </svg>
</script>
    
<script type="text/x-template" id="page-doc">
<div class="page-doc">
    <header data-content1="<header>" data-content2="</header>">
      <h1 data-content1="<h1>" data-content2="</h1>">&hellip;</h1>
      <p class="intro" data-content1='<p class="intro">' data-content2="</p>">&hellip;</p>
    </header>
    <main data-content1="<main>" data-content2="</main>">
      <section id="section1" data-content1='<section id="section1">' data-content2="</section>">
        <h2 data-content1="<h2>" data-content2="</h2>">&hellip;</h2>
        <p data-content1="<p>" data-content2="</p>">&hellip;</p>
        <p data-content1="<p>" data-content2="</p>">&hellip;</p>
      </section>
      <p class='out' data-content1='<p class="out">' data-content2="</p>">&hellip;</p>
    </main>
    <footer data-content1='<footer>' data-content2="</footer>">
      <div class="widget widget1" data-content1='<div class="widget widget1">' data-content2="</div>"><p data-content1="<p>" data-content2="</p>">&hellip;</p></div>
      <div class="widget widget2" data-content1='<div class="widget widget2">' data-content2="</div>">
        <div data-content1="<div>" data-content2="</div>"></div>
      </div>
      <div class="widget widget3" data-content1='<div class="widget widget3">' data-content2="</div>">
        <div class="out" data-content1='<div class="out">' data-content2="</div>">&hellip;</div>
      </div>
    </footer>
  </div>
</script>

            
          
!
            
              :root {
  --red: #ff7058;
  --black: rgb(64, 89, 107);
}
*, *:before, *:after {
  box-sizing: border-box;
}
html {
  font-family: Poppins;
  line-height: 1.5;
  color: var(--black);
}
h1 {
  font-family: Modak;
  font-weight: 400;
  font-size: 3rem;
  font-size: calc(3rem + .25vw + .5vh);
  margin: 2rem 0 0;
}

.app {
  min-height: 100vh;
}

.quiz {
  text-align: center;
  position: fixed;
  right: 40%;
  left:0;
}
.quiz img {
  margin-top: -3rem;
}
.quiz p {
  font-size: calc(1rem + .25vw + .5vh);
  padding: 0 1.5rem;
}
strong {
  color: var(--red);
}
pre {
  font-family: "Anonymous Pro", monospace;
 font-size: calc(1.5rem + .25vw + .5vh);
  color: var(--red); 
}

.page-doc {
  background: #ff705855;
  position: relative;
  margin-left: 60%;
  padding: 0 .25rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.quiz {
  align-items: center;
}
.progress {
  position: fixed;
  top: 0;
  left: 0;
  background: var(--red);
  color: white;
  padding: 0.25rem 1rem;
  font-family: monospace;
}

button {
  font-family: inherit;
  text-transform: uppercase;
  margin: 1.5rem;
  border: 2px solid;
  padding: 1rem 2rem 0.9375rem;
  border-radius: .5rem;
  color: var(--red);
  background: transparent;
  letter-spacing: 2px;
  font-weight: 800;
  cursor: pointer;
  transition: .1s;
  font-size: calc(1rem + .25vw + .5vh);
}
button:hover {
  color: white;
  background: var(--red);
  border-color: var(--red);
}
.score button {
  color: white;
  background: transparent;
}
.score button:hover {
  color: var(--red);
  background: white;
  border-color: white;
}
.correct {
  color: #1698d0;
}
.wrong {
  color: var(--red);
}
.checked.correct {
  animation: yay 1.5s ease-in-out infinite both;
}
@keyframes yay {
  from {
    transform: scale(1);
    transform-origin: center center;
    animation-timing-function: ease-out;
  }
  50% {
    transform: scale(1.3);
    animation-timing-function: ease-out;
  }
}
.checked.wrong {
	animation: shake-horizontal 0.8s cubic-bezier(0.455, 0.030, 0.515, 0.955) both;
}
@keyframes shake-horizontal {
  0%,
  100% {
    transform: translateX(0);
  }
  10%,
  30%,
  50%,
  70% {
    transform: translateX(-10px);
  }
  20%,
  40%,
  60% {
    transform: translateX(10px);
  }
  80% {
    transform: translateX(8px);
  }
  90% {
    transform: translateX(-8px);
  }
}
.label-ctnr {
  display: flex;
  align-items: center;
  justify-content: center;
}
.label-ctnr label {
  position: relative;
  left: -.75rem;
  padding: 0.5rem 1rem 0.5rem 1.5rem;
  border-radius: 5px;
  font-weight: 700;
  text-transform: uppercase;
  font-size: calc(1.5rem + .25vw + .5vh);
  display: flex;
  align-items: center;
  transition: .3s;
  
}
.label-ctnr label span {
  position: absolute;
  left: 0;
}
.label-ctnr:not(.disabled) label:hover {
  cursor: pointer;
}
.label-ctnr:not(.disabled) label:hover {
  transform: scale(1.1);
}
.label-ctnr input {
  opacity: 0;
  position: absolute;
}
.label-ctnr svg {
  width: 1.5rem;
  display: block;
}

.path {
  stroke-dasharray: 1000;
  stroke-dashoffset: 0;
}
 .path.line {
    stroke-dashoffset: 1000;
    animation: dash 1s .15s ease-in-out forwards;
  }
.path.line+.path.line {
    animation: dash .9s .35s ease-in-out forwards;
  }
.path.check {
    stroke-dashoffset: -100;
    animation: dash-check .9s .35s ease-in-out forwards;
  }


@keyframes dash {
  0% {
    stroke-dashoffset: 1000;
  }
  100% {
    stroke-dashoffset: 0;
  }
}


@keyframes dash-check {
  0% {
    stroke-dashoffset: -100;
  }
  100% {
    stroke-dashoffset: 900;
  }
}

.fade-enter-active, .fade-leave-active {
  transition: opacity .5s;
}
.fade-enter, .fade-leave-to {
  opacity: 0;
}

.fade2-enter-active, .fade2-leave-active {
  transition: all 1s 0s ;
  transform: scale(1);
}

.fade2-enter, .fade2-leave-to {
  opacity: 0;
  transform: scale(.5);
}


.score {
  position: fixed;
  background: var(--red);
  color: white;
  top: 0;
  bottom: 0;
  left: 0;
  right:0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

            
          
!
            
              Vue.config.devtools = true

const questions = [
  {
    'selector' : 'p.out',
    'proposal': 'p.out',
    'answer': 'yes' 
  },
  {
    'selector' : 'h2 ~ p',
    'proposal': 'h2 + p',
    'answer': 'no' 
  },
  {
    'selector' : 'h2 ~ p',
    'proposal': 'h2 ~ p',
    'answer': 'yes' 
  },
  {
    'selector' : '#section1',
    'proposal': '[id="section1"]',
    'answer': 'yes' 
  },
  {
    'selector' : 'h2 + p',
    'proposal': 'h2 + p',
    'answer': 'yes' 
  },
  {
    'selector' : 'section p:first-of-type',
    'proposal': 'section p:first-child',
    'answer': 'no' 
  },
  {
    'selector' : 'section p:first-of-type',
    'proposal': 'section p:first-of-type',
    'answer': 'yes' 
  },
  {
    'selector' : 'main > *',
    'proposal': 'main *',
    'answer': 'no' 
  },
  {
    'selector' : 'main > *',
    'proposal': 'main > *',
    'answer': 'yes' 
  },
  {
    'selector' : 'main p',
    'proposal': 'h2 ~ p',
    'answer': 'no' 
  },
  {
    'selector' : 'main > p',
    'proposal': 'main p',
    'answer': 'no' 
  },
  {
    'selector' : 'main > p',
    'proposal': 'main > p',
    'answer': 'yes' 
  },
  {
    'selector' : 'footer div',
    'proposal': 'footer div',
    'answer': 'yes' 
  },
  {
    'selector' : 'footer > div',
    'proposal': 'footer > div',
    'answer': 'yes' 
  },
  {
    'selector' : 'footer > :nth-child(n)',
    'proposal': 'footer > :nth-child(n)',
    'answer': 'yes' 
  },
  {
    'selector' : 'footer > div',
    'proposal': 'footer div',
    'answer': 'no' 
  },
  {
    'selector' : 'footer > :nth-child(2n+1)',
    'proposal': 'footer > :nth-child(2n+1)',
    'answer': 'yes' 
  },
  {
    'selector' : 'footer > :nth-child(2n+1)',
    'proposal': 'footer :nth-child(2n+1)',
    'answer': 'no' 
  },
  {
    'selector' : ':empty',
    'proposal': ':empty',
    'answer': 'yes' 
  },
  {
    'selector' : '[class*="widget"]',
    'proposal': '[class*="widget"]',
    'answer': 'yes' 
  },
  {
    'selector' : '.widget > *',
    'proposal': '.widget > *',
    'answer': 'yes' 
  },
  {
    'selector' : '.widget.widget1',
    'proposal': '.widget.widget1',
    'answer': 'yes' 
  },
  {
    'selector' : 'div.widget1',
    'proposal': 'div.widget1',
    'answer': 'yes' 
  },
  {
    'selector' : '[class^="widget"]',
    'proposal': '[class^="widget"]',
    'answer': 'yes' 
  },
  {
    'selector' : 'section :first-of-type',
    'proposal': 'section :first-of-type',
    'answer': 'yes' 
  }
]

Vue.component( 'question', {
  props: ['v', 'q', 'disabled', 'correct'],
  data() {
    return {
      answer: '',
      a: []
    }
  },
  computed: {
    checked: {
      get() {
        return this.v
      },
      set(val) {
        this.a = val
      }
    },
    displaySelector() {
      return `${this.q} {…}`
    }
  },
  template: `<div>
<pre class="code">{{displaySelector}}</pre>
<div :class="['label-ctnr', disabled ? 'disabled': '']"><label :class="[ feedbackClass(item), checkedClass(item)]" v-for="(item, i) in ['yes', 'no']">
<span v-if="disabled && isChecked(item)">
<svg v-if="isCorrectChecked(item)" version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 130.2 130.2">  
  <polyline class="path check" fill="none" stroke="#1698d0" stroke-width="20" stroke-linecap="round" stroke-miterlimit="10" points="100.2,40.2 51.5,88.8 29.8,67.5 "/>
</svg>
<svg v-else version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 130.2 130.2">  
  <line class="path line" fill="none" stroke="#ff7058" stroke-width="20" stroke-linecap="round" stroke-miterlimit="10" x1="34.4" y1="37.9" x2="95.8" y2="92.3"/>
  <line class="path line" fill="none" stroke="#ff7058" stroke-width="20" stroke-linecap="round" stroke-miterlimit="10" x1="95.8" y1="38" x2="34.4" y2="92.2"/>
</svg>
</span>
<input @change="answerChecked" type="radio" :id="item" :value="item" v-model="checked" :disabled="disabled"/>{{item}}</label></div>

<button v-if="answer" type="button" @click="submitAnswer">Answer</button>
</div>`,
  methods: {
    answerChecked() {
      this.$emit('answered', this.a )
    },
    checkedClass(item) {
        return this.isChecked(item) ? 'checked' : 'not-checked'
    },
    isChecked(item) {
      return item === this.checked 
    },
    isCorrectChecked(item) {
      return item === this.checked && item === this.correct
    },
    feedbackClass(item) {
        if (!this.disabled) {
          return
        }
      return item === this.correct ? 'correct' : 'wrong'
    }
  }
}
)

Vue.component('v-style', {
  render: function (createElement) {
    return createElement('style', this.$slots.default)
  }
});

Vue.component( 'finalresults', {
  props: [ 'finalpercentage'],
  template: "#finalresults"
});

Vue.component('pagedoc', {
  template: '#page-doc',
  data() {
		return {}
	}
});

new Vue({
  el: '#app',
  data() {
    return {
      currentIndex: 0,
      checkedAnswers: [],
      v: [],
      score: 0,
      questions: [],
      isIdle: true,
      askedForResults: false
    }
  },
  computed: {
    total() {
      return this.questions.length 
    },
    finalPercentage() {
      return `${Math.round(this.score/this.total*100)}%`
    },
    proposal() {
      return this.questions[this.currentIndex].proposal
    },
    selector() {
      return this.questions[this.currentIndex].selector
    },
    answer() { 
       return this.questions[this.currentIndex].answer
    },
    isAnswered() {
      return this.v.length !== 0
    },
    disabled() {
      return this.v.length !== 0
    },
    isFinished() {
      return this.currentIndex === this.total - 1
    },
    shouldShowNext() {
      return this.isAnswered && !this.isFinished
    },
    allDone() {
      return this.isAnswered && this.isFinished
    }
  },
  methods: {
    start() {
      this.questions = questions.sort(function(a, b){return 0.5 - Math.random()})
      this.isIdle = false
    },
    go(r) {
    this.v = r
      if (this.checkAnswer(r)) {
        this.score++
      }
      this.disabled = true
      this.isAnswered = true
    },
    checkAnswer(r) {
      return r === this.questions[this.currentIndex].answer
    },
    resetStep() {
      this.isAnswered = false
      this.disabled = false
      this.v = []
    },
    displayNext() {
      this.currentIndex++
      this.resetStep()
    },
    playAgain() {
      this.score = 0
      this.start()
      this.currentIndex = 0
      this.askedForResults = false
      this.resetStep()
    },
    showResults() {
      this.askedForResults = true
      this.isIdle = true
    }
  }
})


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

Console