2017年4月16日日曜日

開発環境

Head First JavaScript Programming (Eric T. Freeman (著)、Elisabeth Robson (著)、O'Reilly Media)の Chapter 5.(A trip to Objectville - Understanding Objects)、Putting it all together… の EXERCISE(No. 2896) を取り組んでみる。

EXERCISE(No. 2896)

コード(Emacs)

HTML5

<button id="run0">run</button><button id="clear0">clear</button>
<pre id="output0"></pre>

<script src="sample2.js"></script>

JavaScript

let btn0 = document.querySelector('#run0'),
    btn1 = document.querySelector('#clear0'),
    pre0 = document.querySelector('#output0'),
    p = (x) => pre0.textContent += x + '\n';

let car = {
    make: 'Chevy',
    model: 'Bel Air',
    year: 1957,
    color: 'red',
    passengers: 2,
    convetible: false,
    mileage: 1021,
};

let cadi = {
    make: 'GM',
    model: 'Cadillac',
    year: 1955,
    color: 'tan',
    passengers: 5,
    convetible: true,
    mileage: 12892,
};
let output = () => {
    p(1);
    Object.keys(car).forEach((k) => {
        p(`${k}: ${car[k]}`);
    });
    p(2);
    Object.keys(cadi).forEach((k) => {
        p(`${k}: ${cadi[k]}`);
    });
};

btn0.onclick = output;

btn1.onclick = () => {
    pre0.textContent = '';
};

output();



    







						

0 コメント:

コメントを投稿