-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaper.js
More file actions
42 lines (35 loc) · 1.46 KB
/
Copy pathpaper.js
File metadata and controls
42 lines (35 loc) · 1.46 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Камень-Ножницы-Бумага</title>
</head>
<body>
<h1>Камень-Ножницы-Бумага</h1>
<p>Выберите: камень, ножницы или бумага.</p>
<button onclick="playGame('камень')">Камень</button>
<button onclick="playGame('ножницы')">Ножницы</button>
<button onclick="playGame('бумага')">Бумага</button>
<p id="result"></p>
<script>
function playGame(userChoice) {
const choices = ['камень', 'ножницы', 'бумага'];
const computerChoice = choices[Math.floor(Math.random() * choices.length)];
let result;
if (userChoice === computerChoice) {
result = 'Ничья!';
} else if (
(userChoice === 'камень' && computerChoice === 'ножницы') ||
(userChoice === 'ножницы' && computerChoice === 'бумага') ||
(userChoice === 'бумага' && computerChoice === 'камень')
) {
result = 'Вы победили!';
} else {
result = 'Вы проиграли!';
}
document.getElementById('result').innerText = `Вы выбрали ${userChoice}. Компьютер выбрал ${computerChoice}. Результат: ${result}`;
}
</script>
</body>
</html>