開発環境
- OS X Lion - Apple(OS)
- Safari、Firefox + Firebug (Webプラウザ、プラグイン)
- BBEdit - Bare Bones Software, Inc.(Text Editor)
- Script言語:JavaScript
- JavaScript Library: jQuery
『初めてのJavaScript 第2版』(シェリー・パワーズ著(Shelley Powers著)、武舎 広幸+武舎 るみ訳、オライリー・ジャパン、2009年、ISBN978-4-87311-425-5) の3章(演算子と文)練習問第3-2.を解いてみる。
その他参考書籍
3-2.
コード(BBEdit)
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);
ちなみにPython3kの場合。
コード(BBEdit)
sample.py
#!/usr/bin/env python3.3
# -*- coding: utf-8 -*-
def f(o):
d = {'one':'OK', 'two':"OK",'three':'OK2'}
if o in d.keys():
print(d[o])
else:
print("NONE")
while True:
o = input()
if o == '': break
f(o)
入出力結果(Terminal)
$ ./sample.py one OK two OK three OK2 four NONE five NONE six NONE seven NONE 12345 NONE $
0 コメント:
コメントを投稿