開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- JavaScript (プログラミング言語)
- Safari(Web browser)
Head First JavaScript Programming (Eric T. Freeman (著)、Elisabeth Robson (著)、O'Reilly Media)の Chapter 3.(Getting functional Introducing Functions)、How the while loop works の CODE MAGNETS(No. 1776)) を取り組んでみる。
CODE MAGNETS(No. 1776))
コード(Emacs)
HTML5
temp = <input id="temp0" type="number" min="1" step="1" value="50"></input> <button id="run0">run</button><button id="clear0">clear</button> <pre id="output0"></pre> <script src="sample1.js"></script>
JavaScript
let input0 = document.querySelector('#temp0'), btn0 = document.querySelector('#run0'), btn1 = document.querySelector('#clear0'), pre0 = document.querySelector('#output0'); let whatShallIWear = (temp) => { if (temp < 60) { pre0.textContent += 'Wear a jacket\n'; } else if (temp < 70) { pre0.textContent += 'Wear a sweater\n'; } else { pre0.textContent += 'Wear t-shert\n'; } }; btn0.onclick = () => { let temp = parseInt(input0.value, 10); whatShallIWear(temp); }; btn1.onclick = () => { pre0.textContent = ''; }; whatShallIWear(60);temp =
0 コメント:
コメントを投稿