Skip to content

Instantly share code, notes, and snippets.

@rskull
Created September 6, 2011 16:28
Show Gist options
  • Save rskull/1198058 to your computer and use it in GitHub Desktop.
Save rskull/1198058 to your computer and use it in GitHub Desktop.
ジャンケンの判定
// 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