Created
September 6, 2011 16:28
-
-
Save rskull/1198058 to your computer and use it in GitHub Desktop.
ジャンケンの判定
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 0 = グー 1 = チョキ 2 = パー | |
function janken (me) { | |
//相手の手 | |
var you = Math.floor(Math.random () * 3); | |
$('me').innerHTML = hand(me); | |
$('you').innerHTML = hand(you); | |
$('res').innerHTML = result(me, you); | |
} | |
//IDの取得 | |
function $(id) { | |
return document.getElementById(id); | |
} | |
//出した手の判定 | |
var hand = Array('グー', 'チョキ', 'パー'); | |
function hand (h) { | |
return hand[h]; | |
} | |
//結果判定 | |
function result (me, you) { | |
if (me == you) { | |
return 'あいこ'; | |
} else if (me == 0) { | |
return you == 1 ? '勝ち' : '負け'; | |
} else if (me == 1) { | |
return you == 2 ? '勝ち' : '負け'; | |
} else { | |
return you == 0 ? '勝ち' : '負け'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment