Files
RCV_TKieu_QuizSpin2_K4_0202…/RCV_QuizSpin2/tdv_sdk.js
lubukhu 797ad5488e
All checks were successful
Deploy to Production / deploy (push) Successful in 6s
up
2026-01-30 19:14:09 +07:00

47 lines
1.1 KiB
JavaScript

let data = []; // thay vì animals
// Hàm load dữ liệu từ file data.json
async function loadData() {
try {
const res = await fetch("data.json");
data = await res.json();
} catch (error) {
console.error("Lỗi load data:", error);
return [];
}
}
// Hàm chọn ngẫu nhiên 4 con và lấy 1 con làm đáp án đúng
function getRandomQuestion() {
if (data.length < 3) {
console.error("Không đủ dữ liệu để chọn!");
return null;
}
// Shuffle
const shuffled = [...data].sort(() => 0.5 - Math.random());
// Lấy 4 con đầu tiên
const options = shuffled.slice(0, 3);
// Chọn 1 trong 4 làm đáp án đúng
const correct = options[Math.floor(Math.random() * options.length)];
window.items = {
options: options,
correct: correct
};
return window.items;
}
function voiceItem(name){
const newAudio = new Audio();
newAudio.src = "https://audio.senaai.vn/audio/en_female_1_"+name.toLowerCase()+".mp3";
newAudio.play();
}
function getImage(name) {
return "https://senaai.tech/games/RCV_QuizSpin2/" + name;
}