-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrockpaperscissors.html
73 lines (54 loc) · 2.13 KB
/
rockpaperscissors.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
<html>
<body>
<script>
function computerplay(){
var val=["rock","paper","scissors"];
return val[Math.floor(Math.random()*val.length)];
}
function game(){
function gameplay(playerselection,computerselection){
playerselection=playerselection.toLowerCase();
if (playerselection==="rock" && computerselection==="scissors"){
pscore++;
}
else if (playerselection==="paper" && computerselection==="rock"){
pscore++;
}
else if (playerselection==="scissors" && computerselection==="paper"){
pscore++;
}
else if (playerselection==="rock" && computerselection==="paper"){
cscore++;
}
else if (playerselection==="paper" && computerselection==="scissors"){
cscore++;
}
else if (playerselection==="scissors" && computerselection==="rock"){
cscore++;
}
else{
/*return "The game ended in a tie";*/
}
}
const playerselection = prompt("Make your choice");
const computerselection = computerplay();
gameplay(playerselection,computerselection);
console.log("your score :"+ pscore + "cpu score :"+cscore)
}
var pscore=0;
var cscore = 0;
for(i=1;i<6;i++){
game(pscore,cscore);
}
if (pscore>cscore){
console.log("you won!");
}
else if (pscore<cscore){
console.log("you lost");
}
else{
console.log("it's a tie");
}
</script>
</body>
</html>