function getRandomCard() {
const cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]; // ค่าไพ่ในเกม
const randomIndex = Math.floor(Math.random() * cards.length); // สุ่มไพ่
return cards[randomIndex];
}
function playBlackjack() {
const card1 = getRandomCard();
const card2 = getRandomCard();
const card3 = getRandomCard();
const totalPoints = card1 + card2 + card3;
console.log(`Cards drawn: ${card1}, ${card2}, ${card3}`);
console.log(`Total points: ${totalPoints}`);
if (totalPoints <= 17) {
console.log("Lose");
} else if (totalPoints === 18) {
console.log("Draw");
} else if (totalPoints > 18 && totalPoints <= 21) {
console.log("Win");
} else {
console.log("Lose");
}
}
// เรียกใช้ฟังก์ชันเพื่อเล่นเกม
playBlackjack();