<html>
<head>
  <title>I Spy Game - Guess the Picture</title>
</head>
<body>
  <h1>I Spy!</h1>
  <p>Can you guess what I'm looking at?</p>
  <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e2/A_house_fly_%28Musca_domestica%29.jpg/220px-A_house_fly_%28Musca_domestica%29.jpg" alt="A house fly" />
  <form action="">
    <label for="guess">Enter your guess:</label><br>
    <input type="text" name="guess" id="guess" />
    <input type="submit" value="Submit Guess" />
  </form>
  <script>
    let answer = 'house fly';
    let form = document.querySelector("form");
    form.addEventListener("submit", function(e) {
      e.preventDefault();
      let guess = document.querySelector("#guess").value;
      if (guess.toLowerCase() === answer) {
        alert("You got it right!");
      } else {
        alert("Sorry, that's not it!");
      }
    });
  </script>
</body>
</html>
Play I Spy: Guess the Picture - Online HTML Game

原文地址: https://www.cveoy.top/t/topic/lnuv 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录