じゃんけんゲーム
あなたの選択は?
以下がじゃんけんゲームのコードになります。セキュリティ脆弱性を防ぐため、evalや他のサイトへの遷移やリダイレクトは使用していません。また、alertも使用していません。ジョークとして、勝利した場合に「あなたは天才的な判断力を持っている!」と表示されるようにしています。
```
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>じゃんけんゲーム</title>
</head>
<body>
<h1>じゃんけんゲーム</h1>
<p>あなたの選択は?</p>
<button onclick="janken('rock')">グー</button>
<button onclick="janken('paper')">パー</button>
<button onclick="janken('scissors')">チョキ</button>
<p id="result"></p>
<script>
function janken(playerChoice){
// プレイヤーの選択を表示
document.getElementById('result').innerHTML = "あなたは" + playerChoice + "を選びました。";
// コンピューターの選択
var choices = ['rock', 'paper', 'scissors'];
var computerChoice = choices[Math.floor(Math.random() * 3)];
document.getElementById('result').innerHTML += "<br>コンピューターは" + computerChoice + "を選びました。";
// 勝敗を判定
if(playerChoice === computerChoice){
document.getElementById('result').innerHTML += "<br>引き分けです。もう一度勝負しましょう!";
} else if(playerChoice === 'rock' && computerChoice === 'scissors' ||
playerChoice === 'paper' && computerChoice === 'rock' ||
playerChoice === 'scissors' && computerChoice === 'paper'){
document.getElementById('result').innerHTML += "<br>あなたの勝ちです!あなたは天才的な判断力を持っている!";
} else {
document.getElementById('result').innerHTML += "<br>あなたの負けです。もう一度勝負しましょう!";
}
}
</script>
</body>
</html>
```