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">
  <h1>数字当てゲーム<small>ver.1.2</small></h1>
  <div>
      <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>
    
    <table v-show="score.length" class="score">
      <caption>★スコア★</caption>
      <tr v-for="(item, index) in score" :class="{'is-minus':item < 0}">
        <th>{{ index + 1 }}回目</th>
        <td>{{ item }}ポイント</td>
      </tr>
    </table>
  <button v-if="limit == 0" @click="reset">もう一度やる</button>    
  </div>
  
  

</div>
              
            
!

CSS

              
                body{
  text-align:center;
  *{
    box-sizing:border-box;
  }
}
.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;
}

.score{
  width:240px;
  margin: 1em auto;
  th,td{
    border-bottom:1px solid #ddd;
  }
  th{
    color: #000;
    background: #ddd;
  }
}
              
            
!

JS

              
                var app = new Vue({
  el: '#app',
  data: {
    name: '',
    random: '?',
    min: 1,
    max: 3,
    point: 0,
    limit: 10,
    result: '',
    score: [],
  },
  methods:{
    input: function(){
      
    },
   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.score.push(this.point);
      //リセット
      this.limit = 10;
      this.point = 0;
      this.random = '?';
      this.result = '';
    }
  }
});
              
            
!
999px

Console