代码示例:(标识:jsck_state_if_prompt)
<!DOCTYPE html>
<html>
<body>

<p>我在想一个字母。猜猜是哪个:a、b、c、d 或 e?</p>

<input id="myInput" type="text">

<button onclick="myFunction()">试一试</button>

<p id="demo"></p>

<script>
function myFunction() {
  var letter = document.getElementById("myInput").value;
  var text;

  // 如果字母是 "c"
  if (letter === "c") {
    text = "Spot on! Good job!";
    
  // 如果字母是 "b" 或 "d"
  } else if (letter === "b" || letter === "d") {
    text = "Close, but not close enough.";
    
  // 如果是其他字母
  } else {
    text = "Waaay off..";
  }
  document.getElementById("demo").innerHTML = text;
}
</script>

</body>
</html>
运行结果: