up
This commit is contained in:
48
New-Words-W19/tdv_sdk.js
Normal file
48
New-Words-W19/tdv_sdk.js
Normal file
@@ -0,0 +1,48 @@
|
||||
let data = [];
|
||||
let currentIndex = -1;
|
||||
|
||||
// Load dữ liệu từ data.json
|
||||
async function loadData() {
|
||||
try {
|
||||
const res = await fetch("data.json");
|
||||
data = await res.json();
|
||||
console.log("Load data OK:", data);
|
||||
} catch (error) {
|
||||
console.error("Lỗi load data:", error);
|
||||
}
|
||||
}
|
||||
|
||||
// Lấy câu hỏi (tiến / lùi)
|
||||
function getRandomQuestion(direction = 0) {
|
||||
if (data.length === 0) {
|
||||
console.error("Chưa load data!");
|
||||
return null;
|
||||
}
|
||||
|
||||
// direction: 0 = tiến, 1 = lùi
|
||||
if (direction === 0) currentIndex++;
|
||||
else if (direction === 1) currentIndex--;
|
||||
|
||||
// Quay vòng
|
||||
if (currentIndex >= data.length) currentIndex = 0;
|
||||
if (currentIndex < 0) currentIndex = data.length - 1;
|
||||
|
||||
const correct = {
|
||||
...data[currentIndex],
|
||||
image: getImage(data[currentIndex].image)
|
||||
};
|
||||
|
||||
window.items = { 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();
|
||||
}
|
||||
|
||||
|
||||
// Hàm tạo URL ảnh
|
||||
function getImage(name) {
|
||||
return "https://senaai.vn/TDV_GAME/Khoi/items/" + name;
|
||||
}
|
||||
Reference in New Issue
Block a user