โค๊ด ที่ผมทำนั้นสุ่มแต่ ตัว audio และปุ่มใส่คำตอบกลับไม่ขึ้น ผมอยากให้ช่วยดูโค๊ดหน่อยครับว่าผมผิดตรงไหน
JavaScript
<script>
function question1()
{
var value = document.getElementById("question1").value;
if (value == 2)
{
window.alert("correct!");
}
else
{
window.alert("try again");
}
}
function question2()
{
var value = document.getElementById("question2").value;
if (value == 3)
{
window.alert("correct!");
}
else
{
window.alert("try again");
}
}
function question3()
{
var value = document.getElementById("question3").value;
if (value == 4)
{
window.alert("correct!");
}
else
{
window.alert("try again");
}
}</script>
<script>
(function () {
var audiosSection = document.getElementById("audios");
var audiosSectionClone = audiosSection.cloneNode();
var audios = audiosSection.getElementsByTagName("audio");
var randomAudio = audios.item(Math.floor(Math.random() * audios.length)).cloneNode(true);
randomAudio.setAttribute("preload", "auto");
audiosSectionClone.appendChild(randomAudio);
audiosSection.parentNode.replaceChild(audiosSectionClone, audiosSection);
})();
(function () {
var audiosSection = document.getElementById("answer");
})();
</script>
HTML
<div id="audios">
<audio class="easy" controls >
<source src="sounds/easy-2.ogg" type="audio/ogg"></audio><br>
<strong>Answer</strong><br>
<input type="text" name="answer" maxlength="1" id="question1"><br>
<button onclick="question1()" >Check if your answer is correct?</button><br>
<audio class="easy" controls >
<source src="sounds/easy-3.ogg" type="audio/ogg"></audio><br>
<strong>Answer</strong><br>
<input type="text" name="answer" maxlength="1" id="question2"><br>
<button onclick="question2()" >Check if your answer is correct?</button><br>
<audio class="easy" controls >
<source src="sounds/easy-4.ogg" type="audio/ogg"></audio><br>
<strong>Answer</strong><br>
<input type="text" name="answer" maxlength="1" id="question3"><br>
<button onclick="question3()" >Check if your answer is correct?</button><br>
<audio class="easy" controls >
<source src="sounds/easy-5.ogg" type="audio/ogg"></audio><br>
<strong>Answer</strong><br>
<input type="text" name="answer" maxlength="1" id="question4"><br>
<button onclick="question4()" >Check if your answer is correct?</button><br>
</div>
Layout ของผมนั้น Randoms แต่วิดิโอครับ ช่องใส่คำตอบไม่ขึ้น
รบกวนผู้รู้ช่วยดูโค๊ดให้ด้วยครับ
ปล.ผมอยู่ม.5ครับ อย่าด่าผมเลยนะครับ
HTML / JavaScript ผมอยากให้เสียงและช่องใส่คำตอบสุ่มไปพร้อมกัน
JavaScript
<script>
function question1()
{
var value = document.getElementById("question1").value;
if (value == 2)
{
window.alert("correct!");
}
else
{
window.alert("try again");
}
}
function question2()
{
var value = document.getElementById("question2").value;
if (value == 3)
{
window.alert("correct!");
}
else
{
window.alert("try again");
}
}
function question3()
{
var value = document.getElementById("question3").value;
if (value == 4)
{
window.alert("correct!");
}
else
{
window.alert("try again");
}
}</script>
<script>
(function () {
var audiosSection = document.getElementById("audios");
var audiosSectionClone = audiosSection.cloneNode();
var audios = audiosSection.getElementsByTagName("audio");
var randomAudio = audios.item(Math.floor(Math.random() * audios.length)).cloneNode(true);
randomAudio.setAttribute("preload", "auto");
audiosSectionClone.appendChild(randomAudio);
audiosSection.parentNode.replaceChild(audiosSectionClone, audiosSection);
})();
(function () {
var audiosSection = document.getElementById("answer");
})();
</script>
HTML
<div id="audios">
<audio class="easy" controls >
<source src="sounds/easy-2.ogg" type="audio/ogg"></audio><br>
<strong>Answer</strong><br>
<input type="text" name="answer" maxlength="1" id="question1"><br>
<button onclick="question1()" >Check if your answer is correct?</button><br>
<audio class="easy" controls >
<source src="sounds/easy-3.ogg" type="audio/ogg"></audio><br>
<strong>Answer</strong><br>
<input type="text" name="answer" maxlength="1" id="question2"><br>
<button onclick="question2()" >Check if your answer is correct?</button><br>
<audio class="easy" controls >
<source src="sounds/easy-4.ogg" type="audio/ogg"></audio><br>
<strong>Answer</strong><br>
<input type="text" name="answer" maxlength="1" id="question3"><br>
<button onclick="question3()" >Check if your answer is correct?</button><br>
<audio class="easy" controls >
<source src="sounds/easy-5.ogg" type="audio/ogg"></audio><br>
<strong>Answer</strong><br>
<input type="text" name="answer" maxlength="1" id="question4"><br>
<button onclick="question4()" >Check if your answer is correct?</button><br>
</div>
Layout ของผมนั้น Randoms แต่วิดิโอครับ ช่องใส่คำตอบไม่ขึ้น
รบกวนผู้รู้ช่วยดูโค๊ดให้ด้วยครับ
ปล.ผมอยู่ม.5ครับ อย่าด่าผมเลยนะครับ