-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex-old.html
114 lines (99 loc) · 2.55 KB
/
index-old.html
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
<html>
<head>
<style>
.div_centrado{
background: yellow;
width: 200px;
height: 50px;
position: absolute;
top:50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
}
</style>
<script>
function machine_random() {
return (Math.floor(Math.random() * 3)+1);
}
function playRound(playerSelection, computerSelection) {
round=playerSelection*computerSelection;
switch (round) {
case 4: case 10: case 18:
result="No one";
break;
case 5: case 12:
result="User";
break;
case 6: case 8: case 15:
result="Machine";
break;
}
return result;
}
function game() {
let index=0;
let user=0;
let machine=0;
let user_num=0;
for (let i = 0; index < 5; index++) {
user_choice = prompt("Enter your choice rock,paper or scissors??");
user_choice=user_choice.toLowerCase();
switch (user_choice) {
case "rock":
user_num=4;
break;
case "paper":
user_num=5;
break;
case "scissors":
user_num=6;
break;
}
machine_num=machine_random();
switch (machine_num) {
case 1:
machine_choice="rock";
break;
case 2:
machine_choice="paper";
break;
case 3:
machine_choice="scissors";
break;
}
winner=playRound(user_num,machine_num);
alert(user_choice+" vs "+machine_choice+"..."+winner+" Wins");
if(winner=="User"){
user=user+1;
}else{
if(winner=="Machine")
{
machine=machine+1;
}else{
}
}
}
if(user>machine){
alert("User wins the game")
}else{
if (user<machine) {
alert("Macine wins the game")
}
else{
alert("Draw")
}
}
}
</script>
</head>
<body>
<form >
<input type="button" class="div_centrado"
onclick="game()"
value="PLAY">
</form>
</body>
</html>
<script>
</script>