Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

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.

HTML

              
                <div id="app">
  <div id="response">
    <!-- the transition will be changed based on truthiness of answer -->
    <transition :name="currentTransition">
      <!-- response is a boolean, so we have toString it for the class name -->
      <!-- true/false class name controls background color -->
      <!-- we have a separate boolean, answerChecked, just to know if an answer was attempted -->
      <div id="notification" :class="response.toString()" v-if="answerChecked">{{ response }}</div>
    </transition>
  </div>

  <div id="problem">
    <!-- very basic form, nothing special -->
    <input v-model="a" readonly /> +
    <input v-model="b" readonly /> =
    <input v-model="answer">
    <button v-if="!answerChecked" @click="check">check</button>
    <button v-else @click="reset">reset</button>
  </div>
  
  <h2 id="instructions">Answer the equation, click check.<br />Click reset to try again.</h2>
</div>

              
            
!

CSS

              
                body {
  background-color: #707070;
  font-family: sans-serif;
  height: 100vh;
  overflow: hidden;
  width: 100vw;
}

#app {
  align-items: center;
  display: flex;
  flex-direction: column;
  height: 100%;
  justify-content: center;
  position: relative;
  width: 100%;
}

#response {
  height: 100px;
}

#notification {
  background-color: gray;
  border: {
    color: black;
    radius: 10px;
    style: solid;
    width: 2px;
  }
  color: white;
  margin: 20px;
  padding: 20px;
  
  // using boolean makes for easy classes
  &.false {
    background-color: #C11826;
  }
  &.true {
    background-color: #307B21;
  }
}

#problem {
  align-items: center;
  background-color: white;
  border: {
    color: black;
    radius: 16px;
    style: solid;
    width: 2px;
  }
  box-sizing: border-box;
  font-size: 24px;
  padding: 16px;
  text-align: center;
  
  input {
    font-size: 24px;
    text-align: center;
    width: 2em;
  }
  button {
    background-color: white;
    border: {
      color: black;
      radius: 10px;
      style: solid;
      width: 2px;
    }
    cursor: pointer;
    font-size: 24px;
    margin-top: 16px;
    width: 100%;
  }
}

#instructions {
  color: white;
  text-align: center;
}

// we are using two animations, based on whether the answer is postive/negative
.positive-enter-active {
  animation: positive 1s;
}
@keyframes positive {
  0% {
    transform: translate3d(0, 0, 0);
  }
  25% {
    transform: translate3d(0, -20px, 0);
  }
  50% {
    transform: translate3d(0, 20px, 0);
  }
  75% {
    transform: translate3d(0, -20px, 0);
  }
  100% {
    transform: translate3d(0, 0, 0);
  }
}

.negative-enter-active {
  animation: negative 1s;
}
@keyframes negative {
  0% {
    transform: translate3d(0, 0, 0);
  }
  25% {
    transform: translate3d(-20px, 0, 0);
  }
  50% {
    transform: translate3d(20px, 0, 0);
  }
  75% {
    transform: translate3d(-20px, 0, 0);
  }
  100% {
    transform: translate3d(0, 0, 0);
  }
}
              
            
!

JS

              
                Vue.component('notification', {
  template: '<div id="notification"><slot></slot></div>'
})

new Vue({
  el: "#app",
  data: {
    // variables for our random equation
    a: 0,
    b: 0,
    // v-model for our answer attempt
    answer: null,
    // is our answer true/false?
    response: false,
    // was answer attempted true/false?
    answerChecked: false,
    // which transition to use
    currentTransition: ''
  },
  methods: {
    // two random numbers for our equation
  	randomProblem: function () {
    	this.a = Math.floor(Math.random() * Math.floor(10));
      this.b = Math.floor(Math.random() * Math.floor(10));
    },
    check: function () {
      // is our answer true/false?
      this.response = this.a + this.b === parseInt(this.answer);
      // an answer was attempted, so true
      this.answerChecked = true;
      // decide which transition we need based on true/false answer attempt
      this.currentTransition = this.response ? 'positive' : 'negative';
    },
    // just reset everything
    reset: function () {
    	this.answer = null;
      this.answerChecked = false;
      this.randomProblem();
    }
  },
  // random equation when we start
  mounted () {
  	this.randomProblem();
  }
})
              
            
!
999px

Console