汉语拼音练习 - 声母韵母标音游戏
<!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><script>
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 += `<p>回答正确!积分+2</p>`;
} else {
score -= 1;
resultDiv.innerHTML += `<p>回答错误!积分-1</p>`;
}
const scoreDiv = document.getElementById('score');
scoreDiv.innerHTML = `积分: ${score}`;
setTimeout(showCharacter, 3000);
}
showCharacter();
</script>
</code></pre>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/o0zv 著作权归作者所有。请勿转载和采集!