開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- JavaScript (プログラミング言語)
- Safari(Web browser)
Head First JavaScript Programming (Eric T. Freeman (著)、Elisabeth Robson (著)、O'Reilly Media)の Chapter 4.(Arrays - Putting Some Order in Your Data)、How to iterate over an array の CODE MAGNETS(No. 2483)) を取り組んでみる。
CODE MAGNETS(No. 2483))
コード(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'); let products = ['Choo Choo Chocolate', 'Icy Mint', 'Cake Batter', 'Bubblegum'], hasButtleGum = [false, false, false, true]; let output = () => { let i = 0; while (i < hasButtleGum.length) { if (hasButtleGum[i]) { pre0.textContent += `${products[i]} contains bubble gum\n`; } i += 1; } }; btn0.onclick = output; btn1.onclick = () => { pre0.textContent = ''; }; output();
0 コメント:
コメントを投稿