-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
47 lines (39 loc) · 1.61 KB
/
main.js
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
let userChoice;
let computerChoice;
let isWinner = false;
let count = 3;
let countUserWin = 0;
let countComputerWin = 0;
const keyWords = ['камень', 'ножницы', 'бумага'];
while (count > 0) {
while (isWinner === false) {
userChoice = prompt(` Напиши: ${keyWords[0]}, ${keyWords[1]} или ${keyWords[2]} `);
userChoice = userChoice.toLowerCase();
if (userChoice === keyWords[0] || userChoice === keyWords[1] || userChoice === keyWords[2]) {
//начинаем игру
const randomNumber = Math.floor(Math.random() * 3);
computerChoice = (keyWords[randomNumber]);
alert(`Компьютер выбрал: ${computerChoice}`);
if (userChoice === computerChoice) {
alert('Ничья, давай еще раз!');
} else if (
(userChoice === keyWords[0] && computerChoice === keyWords[2]) ||
(userChoice === keyWords[1] && computerChoice === keyWords[0]) ||
(userChoice === keyWords[2] && computerChoice === keyWords[1])
) {
alert('Компьютер выйграл!!!');
isWinner = true;
countUserWin++
} else {
alert('Мы победили!!!');
isWinner = true;
countUserWin++
}
} else {
alert("Введите правильное значение");
}
}
count--;
isWinner = false;
}
alert(`Игра закончилась со счетом ${countUserWin} : ${countComputerWin}`);