-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
231 lines (187 loc) · 6.36 KB
/
Copy pathscript.js
File metadata and controls
231 lines (187 loc) · 6.36 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
const button = document.getElementById('goButton');
function setButtonLink() {
if (window.innerWidth <= 768) {
button.onclick = () => location.href = '#games';
} else {
button.onclick = () => location.href = '#games-list';
}
}
setButtonLink();
window.addEventListener('resize', setButtonLink);
const guessNumberGame = () => {
const secretNumber = Math.floor(Math.random() * 100) + 1;
let guess = null;
while (guess !== secretNumber) {
guess = prompt("Угадайте число от 1 до 100:");
if (guess === null) {
alert("Игра отменена");
break;
}
else if (guess === "") {
alert("Введите число от 1 до 100");
}
else if (isNaN(guess)) {
alert("Это не число. Попробуйте снова");
}
else {
guess = Number(guess);
if (guess < 1 || guess > 100) {
alert("Число должно быть от 1 до 100");
}
else if (guess < secretNumber) {
alert("Загаданное число БОЛЬШЕ 📈");
}
else if (guess > secretNumber) {
alert("Загаданное число МЕНЬШЕ 📉");
}
else {
alert(`🎉 Вы угадали число ${secretNumber}!`);
}
}
}
};
function arithmeticTasks() {
const num1 = Math.floor(Math.random() * 10) + 1;
const num2 = Math.floor(Math.random() * 10) + 1;
const operators = ["+", "-", "*", "/"];
const operator = operators[Math.floor(Math.random() * operators.length)];
let question;
let correctAnswer;
if (operator === "/") {
correctAnswer = num1;
const divisible = num1 * num2;
question = `${divisible} / ${num2}`;
}
else if (operator === "+") {
correctAnswer = num1 + num2;
question = `${num1} + ${num2}`;
}
else if (operator === "-") {
correctAnswer = num1 - num2;
question = `${num1} - ${num2}`;
}
else if (operator === "*") {
correctAnswer = num1 * num2;
question = `${num1} * ${num2}`;
}
const answerRaw = prompt(`Решите пример: ${question}`);
if (answerRaw === null) {
alert("Игра отменена");
return;
}
const userAnswer = Number(answerRaw);
if (answerRaw === "" || isNaN(userAnswer)) {
alert("Введите корректное число");
return;
}
if (userAnswer === correctAnswer) {
alert(`Верно!!!`)
}
else {
alert(`Не верно!!! Верный ответ : ${correctAnswer}`);
}
}
function Shifter() {
const userText = prompt(`Введите любое слово или фразу`);
if (userText === null) {
alert("Вы отменили ввод");
return;
}
if (userText === "") {
alert("Вы ничего не ввели");
return;
}
const reversedText = userText.split("").reverse().join("");
alert(reversedText);
}
const quiz = [
{
question: "Какой цвет небо?",
options: ["1. Красный", "2. Синий", "3. Зеленый"],
correctAnswer: 2
},
{
question: "Сколько дней в неделе?",
options: ["1. Шесть", "2. Семь", "3. Восемь"],
correctAnswer: 2
},
{
question: "Сколько у человека пальцев на одной руке?",
options: ["1. Четыре", "2. Пять", "3. Шесть"],
correctAnswer: 2
}
];
function startQuiz() {
let score = 0;
for (let i = 0; i < quiz.length; i++) {
const currentQuestion = quiz[i];
let message = currentQuestion.question + "\n";
message += currentQuestion.options.join("\n");
const answerRaw = prompt(message);
if (answerRaw === null) {
alert("Вы отменили викторину");
return;
}
if (answerRaw === "") {
alert("Вы ничего не ввели");
i--;
continue;
}
const userAnswer = Number(answerRaw);
if (isNaN(userAnswer)) {
alert("Введите корректное число");
i--;
continue;
}
if (userAnswer === currentQuestion.correctAnswer) {
score++;
}
}
alert("Вы ответили правильно на " + score + " из " + quiz.length + " вопросов.");
}
function rockPaperScissors() {
let userChoice = prompt("Выберите: камень, ножницы или бумага");
if (userChoice === null) {
alert("Вы отменили игру");
return;
}
userChoice = userChoice.trim().toLowerCase();
if (userChoice === "") {
alert("Вы ничего не ввели");
return;
}
const options = ["камень", "ножницы", "бумага"];
if (!options.includes(userChoice)) {
alert("Введите корректный вариант: камень, ножницы или бумага");
return;
}
function getRandomIndex(max) {
return Math.floor(Math.random() * max);
}
const computerChoice = options[getRandomIndex(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
);
}
const btn_color = document.querySelector('#btn_color');
btn_color.addEventListener("click", () => {
let r = Math.floor(Math.random() * 256);
let g = Math.floor(Math.random() * 256);
let b = Math.floor(Math.random() * 256);
let color = (`rgb(${r}, ${g}, ${b})`);
document.querySelector('main').style.backgroundColor = color;
})