-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
207 lines (162 loc) · 6.41 KB
/
script.js
File metadata and controls
207 lines (162 loc) · 6.41 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
function startGameOne() {
const randomNumber = Math.floor(Math.random() * 100) + 1;
let guessedCorrectly = false;
alert("Привет! Начинаем игру 'Угадай Число'.\nЯ загадал число от 1 до 100.");
while (!guessedCorrectly) {
let userInput = prompt("Введи свое предположение (число от 1 до 100). Если хочешь сдаться, нажми 'Отмена'.");
if (userInput === null) {
alert('Игра окончена.');
return;
}
const userGuess = parseInt(userInput);
if (isNaN(userGuess)) {
alert('Ошибка! Введи целое число.');
continue;
}
if (userGuess < 1 || userGuess > 100) {
alert("Число должно быть в диапазоне от 1 до 100. Попробуй еще раз.");
continue;
}
if (userGuess < randomNumber) {
alert(`Загаданное число БОЛЬШЕ, чем ${userGuess}. Попробуй еще!`);
} else if (userGuess > randomNumber) {
alert(`Загаданное число МЕНЬШЕ, чем ${userGuess}. Попробуй еще!`);
} else {
guessedCorrectly = true;
alert(`🎉 Поздравляю! Ты угадал! Загаданное число было ${randomNumber}.`);
}
}
}
function startMathGame() {
let num1, num2, operation, question, correctAnswer;
let operations = ["+", "-", "*", "/"];
operation = operations[Math.floor(Math.random() * operations.length)];
if (operation === "/") {
num2 = Math.floor(Math.random() * 19) + 1;
correctAnswer = Math.floor(Math.random() * 10) + 1;
num1 = num2 * correctAnswer;
} else {
num1 = Math.floor(Math.random() * 20) + 1;
num2 = Math.floor(Math.random() * 20) + 1;
switch (operation) {
case "+":
correctAnswer = num1 + num2;
break;
case "-":
correctAnswer = num1 - num2;
break;
case "*":
correctAnswer = num1 * num2;
break;
}
}
question = `${num1} ${operation} ${num2}`;
let userAnswer = prompt(`Реши пример: ${question}`);
if (Number(userAnswer) === correctAnswer) {
alert("Верно!");
} else {
alert(`Ошибка! Правильный ответ: ${correctAnswer}`);
}
}
// Игра "Камень, ножницы, бумага"
const playGameRockPaperScissors = () => {
const choices = ["камень", "ножницы", "бумага"];
let userChoice = prompt("Выберите: камень, ножницы или бумага");
if (userChoice === null) {
alert("Игра отменена");
return;
}
userChoice = userChoice.toLowerCase().trim();
if (!choices.includes(userChoice)) {
alert("Некорректный выбор! Попробуйте еще раз.");
return;
}
const randomIndex = Math.floor(Math.random() * choices.length);
const computerChoice = choices[randomIndex];
let result;
if (userChoice === computerChoice) {
result = "Ничья!";
} else if (
(userChoice === "камень" && computerChoice === "ножницы") ||
(userChoice === "ножницы" && computerChoice === "бумага") ||
(userChoice === "бумага" && computerChoice === "камень")
) {
result = "Вы выиграли!";
} else {
result = "Вы проиграли!";
}
alert(`Ваш выбор: ${userChoice}\nВыбор компьютера: ${computerChoice}\nРезультат: ${result}`);
};
function startReverseTextGame() {
let userText = prompt("Введите текст, который нужно перевернуть:");
if (userText !== null) {
let reversed = userText.split("").reverse().join("");
alert("Перевернутый текст: " + reversed);
}
}
function startQuizGame() {
const quiz = [
{
question: "Какой цвет небо?",
options: ["1. Красный", "2. Синий", "3. Зеленый"],
correctAnswer: 2
},
{
question: "Сколько дней в неделе?",
options: ["1. Шесть", "2. Семь", "3. Восемь"],
correctAnswer: 2
},
{
question: "Сколько у человека пальцев на одной руке?",
options: ["1. Четыре", "2. Пять", "3. Шесть"],
correctAnswer: 2
}
];
let score = 0;
for (let i = 0; i < quiz.length; i++) {
let q = quiz[i];
let userAnswer = prompt(q.question + "\n" + q.options.join("\n"));
if (Number(userAnswer) === q.correctAnswer) {
score++;
}
}
alert("Вы ответили правильно на " + score + " из " + quiz.length + " вопросов!");
}
function playRockPaperScissors() {
const options = ["камень", "ножницы", "бумага"];
let userChoice = prompt("Выберите: камень, ножницы или бумага").toLowerCase();
if (!options.includes(userChoice)) {
alert("Ошибка! Нужно ввести: камень, ножницы или бумага.");
return;
}
let computerChoice = options[Math.floor(Math.random() * options.length)];
let result = "";
if (userChoice === computerChoice) {
result = "Ничья!";
} else if (
(userChoice === "камень" && computerChoice === "ножницы") ||
(userChoice === "ножницы" && computerChoice === "бумага") ||
(userChoice === "бумага" && computerChoice === "камень")
) {
result = "Вы выиграли! 🎉";
} else {
result = "Вы проиграли 😢";
}
alert(
"Ваш выбор: " + userChoice +
"\nВыбор компьютера: " + computerChoice +
"\nРезультат: " + result
);
}
function startRandomColorGame() {
const letters = "0123456789ABCDEF";
let color = "#";
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
const sections = document.querySelectorAll(".about-games, .mini-games");
sections.forEach(section => {
section.style.backgroundColor = color;
});
alert("Новый случайный цвет: " + color);
}