開発環境
- OS X Lion - Apple(OS)
- Safari、Firefox + Firebug (Webプラウザ、プラグイン)
- BBEdit - Bare Bones Software, Inc.(Text Editor)
- プログラミング言語:JavaScript
- JavaScript Library: jQuery
『初めてのJavaScript 第2版』(シェリー・パワーズ著(Shelley Powers著)、武舎 広幸+武舎 るみ訳、オライリー・ジャパン、2009年、ISBN978-4-87311-425-5) の3章(演算子と文)練習問第3-2.を解いてみる。
その他参考書籍
2.
出力
コード(BBEdit)
HTML
<label>式: <input id="t0" type="text" value="one" onkeyup="try{
eval($('#pre1').text());
} catch (e) {
alert(e);
}" /></label>
JavaScript
(function ( ) {
var a = $('#t0').val(),
result;
switch ( a ) {
case "one":
case "two":
result = "OK";
break;
case "three":
result = "OK2";
break;
default:
result = "NONE";
}
$('#pre0').text(result);
})();
ちなみにPython3.3の場合。
コード(BBEdit)
sample.py
#!/usr/bin/env python3.3
# -*- coding: utf-8 -*-
import re
d = {'one':'OK','two':'OK','three':'OK1'}
while True:
a = input()
if re.search(r"^\s*$", a):
break
if a in d.keys():
print(d[a])
else:
print("NONE")
入出力結果(Terminal)
$ ./sample.py one OK two OK three OK1 four NONE $
0 コメント:
コメントを投稿