Start text flashing lottery with given food options.

HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>版本7 - 文字閃爍抽籤</title>
<style>
  #result { font-size: 2em; margin: 20px; }
  button { padding: 10px 20px; }
</style>
</head>
<body>
  <h2>今天中午吃什麼?</h2>
  <div id="result">???</div>
  <button onclick="draw()">開始抽籤</button>

<script>
const foods = ["壽司","牛排","滷肉飯","火鍋","拉麵"];

let counter = 0;       // 記錄次數
let intervalId = null; // 存放 setInterval 的 ID

function changeFood() {
  const pick = foods[Math.floor(Math.random() * foods.length)];
  document.getElementById("result").innerText = pick;
  counter++;
  if (counter > 10) {
    clearInterval(intervalId); // 停止
  }
}

function draw() {
  counter = 0;  // 重新開始
  intervalId = setInterval(changeFood, 100); // 每0.1秒呼叫 changeFood
}
</script>
</body>
</html>