2017年4月6日木曜日

開発環境

Head First HTML5 Programming (Elisabeth Robson (著)、Eric Freeman (著)、O'Reilly Media)の Chapter 2.(Introducing JavaScript and the DOM: A Little Code)、Make decisions with JavaScript の SHARPEN YOUR PENCIL(No. 1590) を取り組んでみる。

SHARPEN YOUR PENCIL(No. 1590)

コード(Emacs)

HTML5

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

<h1>My awesome playlist</h1>
<ul id="playlist0">
  <li id="song1"></li>
  <li id="song2"></li>
  <li id="song3"></li>
</ul>

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

JavaScript

let btn0 = document.querySelector('#run0'),
    btn1 = document.querySelector('#clear0');

let addSongs = () => {
    let song1 = document.querySelector('#song1'),
        song2 = document.querySelector('#song2'),
        song3 = document.querySelector('#song3');

    song1.textContent = 'Blue Suede Strings, by Elvis Pagely';
    song2.textContent = 'Greet Objects on Fire, by Jerry JSON Lewis';
    song3.textContent = 'I Code the line, by Johnny JavaScript';
};

btn0.onclick = addSongs;

btn1.onclick = () => {
    let song1 = document.querySelector('#song1'),
        song2 = document.querySelector('#song2'),
        song3 = document.querySelector('#song3');

    song1.textContent = '';
    song2.textContent = '';
    song3.textContent = '';
};

addSongs();

My awesome playlist

0 コメント:

コメントを投稿