Pen Settings

HTML

CSS

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

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                <div id="app">
  
  <h1>数字当てゲーム</h1>
  <p>
    選んだ数字とランダム数字が一致すると選んだ数字をポイントに加算。<br>
    はずれると選んだ数字の分、ポイントが減ります。<br>
  </p>
  
  <div v-if="limit != 0">
    <dl :class="{ 'is-correct': result, 'is-incorrect': result === false }">
      <dt class="random">{{ random }}</dt>
      <dd>
        <button @click="sum(1)">1</button>
        <button @click="sum(2)">2</button>
        <button @click="sum(3)">3</button>
      </dd>
    </dl>
        
    <p>ボタンを押せるのはあと{{ limit }}回です</p>
  </div>
  <dl>
    <dt>あなたのポイント</dt>
    <dd class="point" :class="{'is-minus':point < 0}">{{ point }}</dd>
  </dl>
  
  <button v-if="limit == 0" @click="reset">リセット</button>
</div>
              
            
!

CSS

              
                
body{
  text-align:center;
}
.random{
  font-size: 3em;
}

.point{
  font-size: 3em;
  line-height:1;
  margin-top:0;
}

dl{
  border:4px solid #ddd;
  padding: 10px;
  width:240px;
  margin: 1em auto;
  &.is-correct{
    border-color: blue;
    color: blue;
  }
  &.is-incorrect{
    border-color: red;
    color: red;
  }
}
dd{
  margin:0;
  font-weight:bold;
}

.is-minus{
  color:red;
}
              
            
!

JS

              
                var app = new Vue({
  el: '#app',
  data: {
    random: '?',
    min: 1,
    max: 3,
    point: 0,
    limit: 10,
    result: ''
  },
  methods:{
   sum: function(el){
     //ランダムで整数を出す
      this.random = Math.floor( Math.random() * (this.max + 1 - this.min) ) + this.min ;
     //ランダム数字と比較
     if(el == this.random){
       this.point += el;
       this.result = true;
     }else{
        this.point -= el;
        this.result = false;
     }
     //回数のカウントダウン
     this.limit -= 1;
   },
    reset: function(){
      this.limit = 10;
      this.point = 0;
      this.random = '?';
      this.result = '';
    }
  }
});

              
            
!
999px

Console