<!DOCTYPE html>
<html>
<head>
    <meta charset='UTF-8'>
    <title>声母韵母标音</title>
    <style>
        body {
            font-family: Arial, sans-serif;
        }
        #score {
            position: absolute;
            top: 10px;
            right: 10px;
            font-size: 24px;
        }
        #result {
            position: absolute;
            top: 50px;
            left: 50px;
            font-size: 36px;
        }
    </style>
</head>
<body>
    <div id='score'>积分: 0</div>
    <div id='result'></div>
<pre><code>&lt;script&gt;
    const initials = [
        { symbol: 'b', audio: 'audio1.mp3', image: 'image1.jpg' },
        { symbol: 'p', audio: 'audio2.mp3', image: 'image2.jpg' },
        // ... add more initials
    ];

    const finals = [
        { symbol: 'a', audio: 'audio3.mp3', image: 'image3.jpg' },
        { symbol: 'o', audio: 'audio4.mp3', image: 'image4.jpg' },
        // ... add more finals
    ];

    const characters = [
        '汉', '字', '随', '机', '标', '音', '拉', '取', '上', '面' // ... add more characters
    ];

    let score = 0;

    function getRandomInt(max) {
        return Math.floor(Math.random() * max);
    }

    function showCharacter() {
        const randomIndex = getRandomInt(characters.length);
        const character = characters[randomIndex];
        const randomInitialIndex = getRandomInt(initials.length);
        const randomFinalIndex = getRandomInt(finals.length);
        const initial = initials[randomInitialIndex];
        const final = finals[randomFinalIndex];

        const audio = document.createElement('audio');
        audio.src = initial.audio;
        audio.play();

        const image = document.createElement('img');
        image.src = initial.image;
        image.alt = character;
        image.style.width = '100px';

        const resultDiv = document.getElementById('result');
        resultDiv.innerHTML = '';
        resultDiv.appendChild(image);

        const answer = initial.symbol + final.symbol;
        const guessedAnswer = prompt(`请为汉字'${character}'标注声母和韵母(例:${answer})`);
        if (guessedAnswer === answer) {
            score += 2;
            resultDiv.innerHTML += `&lt;p&gt;回答正确!积分+2&lt;/p&gt;`;
        } else {
            score -= 1;
            resultDiv.innerHTML += `&lt;p&gt;回答错误!积分-1&lt;/p&gt;`;
        }

        const scoreDiv = document.getElementById('score');
        scoreDiv.innerHTML = `积分: ${score}`;

        setTimeout(showCharacter, 3000);
    }

    showCharacter();
&lt;/script&gt;
</code></pre>
</body>
</html>

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

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