-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
67 lines (58 loc) · 2.07 KB
/
script.js
File metadata and controls
67 lines (58 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
let requestCount = 0;
const choices = ["tosh", "qaychi", "qogoz"];
let currentUser = '';
function getRiggedChoice(userChoice) {
requestCount++;
let botChoice = "";
if (requestCount % 3 === 1) {
botChoice = {
"tosh": "qaychi",
"qaychi": "qogoz",
"qogoz": "tosh"
}[userChoice]; // User wins
} else if (requestCount % 3 === 2) {
botChoice = {
"tosh": "qogoz",
"qaychi": "tosh",
"qogoz": "qaychi"
}[userChoice]; // User loses
} else {
botChoice = userChoice; // Tie
}
return botChoice;
}
function displayResult(userChoice, botChoice) {
const resultText = document.getElementById("result");
const userChoiceElement = document.getElementById("user-choice");
const botChoiceElement = document.getElementById("bot-choice");
userChoiceElement.textContent = userChoice;
botChoiceElement.textContent = botChoice;
if (userChoice === botChoice) {
resultText.textContent = "Tenglik! 🤝";
} else if (
(userChoice === "tosh" && botChoice === "qaychi") ||
(userChoice === "qaychi" && botChoice === "qogoz") ||
(userChoice === "qogoz" && botChoice === "tosh")
) {
resultText.textContent = "Siz yutdingiz! 🎉";
} else {
resultText.textContent = "Siz yutqazdingiz! 😢";
}
}
function login() {
currentUser = document.getElementById('username').value;
if (currentUser) {
document.getElementById('user-login').style.display = 'none';
document.getElementById('game-screen').style.display = 'block';
} else {
alert("Iltimos, foydalanuvchi nomini kiriting.");
}
}
document.getElementById("login-btn").addEventListener("click", login);
document.querySelectorAll(".choice-btn").forEach(button => {
button.addEventListener("click", () => {
const userChoice = button.id;
const botChoice = getRiggedChoice(userChoice);
displayResult(userChoice, botChoice);
});
});