2016年9月11日日曜日

開発環境

Exercises for Programmers: 57 Challenges to Develop Your Coding Skills (Brian P. Hogan 著、Pragmatic Bookshelf)のChapter 6(Repetition)、31(Karvonen Heart Rate)を取り組んでみる。

31(Karvonen Heart Rate)

コード(Emacs)

<label for="heart_rate0">
  Resting Pulse:
</label>
<input id="heart_rate0" type="number" min="0" max="999" step="1" value="65">
<label for="age0">
  Age:
</label>
<input id="age0" type="number" size="3" min="1" max="999" step="1" value="22">
<br>
<br>
<div id="output0"></div>
<br>
<label for="intensity0">
  Intensity:
</label>
<input id="intensity0" type="range" min="55" max="95" step="5" value="55">
<script src="array.js"></script>
<script src="sample31.js"></script>
(function () {
    'use strict';
    var div_output = document.querySelector('#output0'),
        input_heart_rate = document.querySelector('#heart_rate0'),
        input_age = document.querySelector('#age0'),
        input_intensity = document.querySelector('#intensity0'),
        inputs = [input_heart_rate, input_age, input_intensity],
        targetHeartRate,
        output;

    targetHeartRate = function (age, heart_rate, intensity) {
        return Math.round(
            (220 - age - heart_rate) * intensity / 100 + heart_rate);
    };

    output = function () {
        var heart_rate = parseInt(input_heart_rate.value, 10),
            age = parseInt(input_age.value, 10),
            intensity = parseInt(input_intensity.value, 10),
            rate = targetHeartRate(age, heart_rate, intensity);

        div_output.innerText =
            'Intensity: ' + intensity + '%, Rate: ' + rate + 'bpm'
    };

    console.log(inputs);
    inputs.forEach(function (input) {
        input.onchange = output;
    });

    output();
}());



0 コメント:

コメントを投稿

Comments on Google+: