forked from kokonior/Javascript-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgubakuSederhana.js
57 lines (50 loc) · 1.87 KB
/
gubakuSederhana.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
48
49
50
51
52
53
54
55
56
57
let again = true;
const start = alert('Welcome To GUBAKU GAMES\nBy Daniansyah\n\nYou have 3 Life');
while (again) {
for (let i = 3; i > 0; i--) {
let player = prompt('Choose Character : gunting, batu, kertas');
let nyawa = i - 1;
if (nyawa == 2) {
nyawa = 'You have 2 Life';
} else if (nyawa == 1) {
nyawa = 'Hurry Up, left 1 life again';
} else {
nyawa = 'Uuupsss, GAME OVER';
}
let comp = Math.random();
if (comp < 0.34) {
comp = 'gunting';
} else if (comp >= 0.34 && comp <= 0.66) {
comp = 'batu';
} else {
comp = 'kertas';
}
let result = '';
if (player == comp) {
result = 'DRAW!';
} else if (player == 'gunting') {
result = (comp == 'batu') ? 'LOSE!' : 'WIN!';
} else if (player == 'batu') {
result = (comp == 'kertas') ? 'LOSE!' : 'WIN!';
} else if (player == 'kertas') {
result = (comp == 'gunting') ? 'LOSE!' : 'WIN!';
} else {
result = 'False input, Lets Try again!';
}
if (result == 'WIN!') {
alert(`You : ${player}\nComputer : ${comp}\n\nCongratulations You ${result}`);
i = 0;
} else if (result == 'LOSE!') {
alert(`You : ${player}\nComputer : ${comp}\n\nOh No, You ${result}\n\n${nyawa}`);
} else if (result == 'DRAW!') {
alert(`You : ${player}\nComputer : ${comp}\n\nHuuuhhh, You ${result}\n\n${nyawa}`);
} else if (player == null) {
alert(`Canceled, Your Games was ended`);
i = 0;
} else {
alert(`You : ${player}\n\nSorry ${result}\n\n${nyawa}`);
}
}
again = confirm('Play again ?');
}
alert('Computer : Thank You');