2016年8月25日木曜日

開発環境

Exercises for Programmers: 57 Challenges to Develop Your Coding Skills (Brian P. Hogan 著、Pragmatic Bookshelf)のChapter 4(Making Decisions)、16(Legal Driving Age)を取り組んでみる。

16(Legal Driving Age)

コード(Emacs)

<p>
  <label for="age0">
    What is your age? 
  </label>
  <input id="age0" type="number" min="0" max="1000" step="1" value="15">
</p>
<p id="output0"></p>

<script src="sample16.js"></script>
(function () {
    'use strict';
    var legal_age = 16,
        
        input_age = document.querySelector('#age0'),
        p_output = document.querySelector('#output0'),
        
        display;

    display = function () {
        var age = parseInt(input_age.value, 10);

        p_output.innerText =
            age < legal_age ?
            'You are not old enough to legally drive.' :
            'You are old enought to legally drive.';
    };

    input_age.onkeyup = display;
    input_age.onchange = display;

    display();
}());

0 コメント:

コメントを投稿

Comments on Google+: