Randomly selects lunch option between rice or noodles
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<h2 id="result">今天中午吃什麼?</h2>
<button onclick="pickFood()">抽籤!</button>
<script>
function pickFood() {
let rand = Math.random(); // 0 ~ 1 之間
if (rand < 0.5) {
document.getElementById("result").innerText = "便當";
} else {
document.getElementById("result").innerText = "炒飯";
}
}
</script>
</body>
</html>