開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- JavaScript (プログラミング言語)
- Node.js, Safari(JavaScript エンジン)
- Learning JavaScript [邦訳](参考書籍)
Head First Python (Paul Barry (著)、O'Reilly Media)のChapter 2.(List Data: Working with Ordered Data)、Reviewing Our Experiments の SHARPEN YOUR PENCIL(No. 1802) を JavaScript で取り組んでみる。
SHARPEN YOUR PENCIL(No. 1802)
コード(Emacs)
HTML5
<pre id="output0"></pre> <button id="run0">run</button> <button id="clear0">clear</button> <script src="sample2.js"></script>
JavaScript
let pre0 = document.querySelector('#output0'),
btn0 = document.querySelector('#run0'),
btn1 = document.querySelector('#clear0'),
range = (start, end, step=1) => {
let res = [];
for (let i = start; i < end; i += step) {
res.push(i);
}
return res;
},
p = (x) => pre0.textContent += x + '\n';
let output = () => {
let phrase = "Don't panic!",
plist = phrase.split('');
p(phrase);
p(plist);
let newPhrase = plist.slice(1, 3).join('');
newPhrase += `${plist[5]}${plist[4]}${plist[7]}${plist[6]}`;
p(plist);
p(newPhrase);
};
let clear = () => pre0.textContent = '';
btn0.onclick = output;
btn1.onclick = clear;
output();
0 コメント:
コメントを投稿