開発環境
- OS X El Capitan - Apple (OS)
- Emacs (Text Editor)
- JavaScript (プログラミング言語)
- jQuery (Library)
- Safari(Web browser)
Exercises for Programmers: 57 Challenges to Develop Your Coding Skills (Brian P. Hogan 著、Pragmatic Bookshelf)のChapter 2(Input, Processing, and Output)、2(Counting the Number of Characters)を取り組んでみる。
2(Counting the Number of Characters)
コード(Emacs)
<p>
<label for="input0">
What is the input string? <input id="input0" type="text" value="Homer">
</label>
</p>
<p id="output0"></p>
<script src="sample2.js"></script>
var input = document.querySelector('#input0'),
output = document.querySelector('#output0'),
s,
count;
count = function () {
s = input.value;
if (s === '') {
output.innerHTML = 'must enter something';
} else {
output.innerHTML = s + ' has ' + s.length + ' characters.';
}
};
count();
input.onkeyup = count;
0 コメント:
コメントを投稿