以下是一个简单的示例代码,实现了你所描述的功能:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>声母韵母标音练习</title>
  <style>
    #score {
      position: fixed;
      top: 10px;
      right: 10px;
      font-size: 20px;
    }
  </style>
</head>
<body>
  <h1>声母韵母标音练习</h1>
  <h2>请标出以下随机汉字的声母和韵母组合:</h2>
  <p id="word"></p>
  <img id="image" src="" alt="图片1">
  <audio id="audio" src="" controls></audio>
  <div id="score">积分: 0</div>

  <script>
    // 声母韵母组合数据
    const combinations = [
      { word: '爸', consonant: 'b', vowel: 'a' },
      { word: '妈', consonant: 'm', vowel: 'a' },
      { word: '塔', consonant: 't', vowel: 'a' },
      // 其他组合...
    ];

    let score = 0; // 积分

    // 随机选择一个组合
    function getRandomCombination() {
      const randomIndex = Math.floor(Math.random() * combinations.length);
      return combinations[randomIndex];
    }

    // 更新显示的字、图片和声音
    function updateDisplay(combination) {
      const wordElement = document.getElementById('word');
      const imageElement = document.getElementById('image');
      const audioElement = document.getElementById('audio');

      wordElement.textContent = combination.word;
      imageElement.src = 'image1.jpg'; // 图片1的路径
      audioElement.src = 'sound1.mp3'; // 声音1的路径
    }

    // 处理回答正确的情况
    function handleCorrectAnswer() {
      score += 2;
      document.getElementById('score').textContent = `积分: ${score}`;
    }

    // 处理回答错误的情况
    function handleWrongAnswer() {
      score -= 1;
      document.getElementById('score').textContent = `积分: ${score}`;
      document.getElementById('image').src = 'image2.jpg'; // 图片2的路径
      document.getElementById('audio').src = 'sound2.mp3'; // 声音2的路径
    }

    // 监听用户回答
    document.addEventListener('keydown', function(event) {
      if (event.key === ' ') { // 用户按下空格键
        const currentCombination = getRandomCombination();
        updateDisplay(currentCombination);
      } else if (event.key === 'Enter') { // 用户按下回车键
        const userInput = prompt('请输入你认为的声母和韵母组合(例如:b-a)');
        const [userConsonant, userVowel] = userInput.split('-');
        const currentCombination = getRandomCombination();

        if (
          userConsonant.toLowerCase() === currentCombination.consonant
          && userVowel.toLowerCase() === currentCombination.vowel
        ) {
          handleCorrectAnswer();
        } else {
          handleWrongAnswer();
        }
      }
    });
  </script>
</body>
</html>

注意:以上代码只是一个简单示例,实际开发中可能需要更多的功能和优化。还需要准备好正确和错误的图片和声音文件,并将其路径替换到代码中的image1.jpg、sound1.mp3、image2.jpg、sound2.mp3处。


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

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