開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Safari、Firefox + Firebug (Webプラウザ、プラグイン)
- JavaScript (プログラミング言語)
- jQuery (JavaScript Library)
『初めてのJavaScript 第2版』(シェリー・パワーズ著(Shelley Powers著)、武舎 広幸+武舎 るみ訳、オライリージャパン、2009年、ISBN978-4-87311-425-5) の8章(フォームと検証)、練習問第8-1.を解いてみる。
その他参考書籍
練習問第8-1.
コード(BBEdit)
var result = 'どれかひとつ、色を選んで下さい。', d0 = $('#d0'), colors = d0.children(), n, i, max; for (i = 0, max = colors.length; i < max; i += 1){ if (colors[i].checked){ n = Math.random(); result = n > 0.7 ? '大吉' : n > 0.4 ? '中吉' : n > 0.1 ? '小吉' : '凶'; } } $('#pre0').text(result);
赤
青
黄色
白
0 コメント:
コメントを投稿