馬レース
勝つ馬を選んでタッチしてください。
以下が実装例です。セキュリティ脆弱性を避けるため、evalを使わず、他のサイトに遷移させたりリダイレクトさせたりはしません。また、alertも使用しません。
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>馬レース</title>
</head>
<body>
<h1>馬レース</h1>
<p>勝つ馬を選んでタッチしてください。</p>
<div>
<img src="https://www.clipartkey.com/mpngs/m/120-1202344_horse-icons-horse-icon-png.png" alt="馬1" id="horse1">
<img src="https://www.clipartkey.com/mpngs/m/120-1202344_horse-icons-horse-icon-png.png" alt="馬2" id="horse2">
</div>
<button onclick="startRace()">レース開始</button>
<script>
function startRace() {
// 2頭の馬のスピードをランダムに設定
var horse1Speed = Math.floor(Math.random() * 5) + 1;
var horse2Speed = Math.floor(Math.random() * 5) + 1;
// 馬の走り始めた場所
var horse1Position = 0;
var horse2Position = 0;
// レースの長さ
var raceLength = 100;
// 馬の走るスピードを1秒ごとに更新
var intervalId = setInterval(function() {
horse1Position += horse1Speed;
horse2Position += horse2Speed;
// 馬の位置が画面外に出ないように調整
if(horse1Position > raceLength) {
horse1Position = raceLength;
}
if(horse2Position > raceLength) {
horse2Position = raceLength;
}
// 馬を画面上で移動させる
document.getElementById("horse1").style.paddingLeft = horse1Position + "px";
document.getElementById("horse2").style.paddingLeft = horse2Position + "px";
// ゴールした馬を判定
if(horse1Position >= raceLength || horse2Position >= raceLength) {
clearInterval(intervalId);
if(horse1Position > horse2Position) {
// 馬1が勝利
document.getElementById("horse1").alt += " 優勝";
document.getElementById("horse2").alt += " 敗北";
var joke = "馬1: 今日はごめんなさい、次回は絶対に勝ちます!";
} else {
// 馬2が勝利
document.getElementById("horse2").alt += " 優勝";
document.getElementById("horse1").alt += " 敗北";
var joke = "馬2: ええっと、勝つことができたのは縁起の良い名前のおかげかなぁ?";
}
document.body.innerHTML += "<p>" + joke + "</p>";
}
}, 1000);
}
</script>
</body>
</html>
```
このプログラムでは、2頭の馬の画像を表示し、レース開始ボタンをクリックするとレースが始まります。勝った馬には「優勝」と表示され、負けた馬には「敗北」と表示されます。また、それぞれの馬がレース中に喋るジョークが表示されます。