-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
96 lines (91 loc) · 3.7 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rock Paper Scissors</title>
</head>
<body>
<script>
function computerPlay() {
let availablePlays = ['Rock', 'Paper', 'Scissors'];
return availablePlays[Math.floor(Math.random() * availablePlays.length)];
}
/* function playRound(playerSelection, computerSelection) {
let playerSelect = playerSelection.toLowerCase();
if (playerSelect !== 'rock' && playerSelect !== 'paper' && playerSelect !== 'scissors') {
return 'You must enter a valid option (rock, paper or scissors)';
}
let computerSelect = computerSelection.toLowerCase();
if (playerSelect === computerSelect) {
return 'Tied game';
} else if (playerSelect === 'rock') {
if (computerSelect === 'paper') {
return 'You lose! Paper beats Rock';
} else {
return 'You win! Rock beats Scissors';
}
} else if (playerSelect === 'paper') {
if (computerSelect === 'rock') {
return 'You win! Paper beats Rock';
} else {
return 'You lose! Scissors beat Paper';
}
} else {
if (computerSelect === 'rock') {
return 'You lose! Rock beats Scissors';
} else {
return 'You win! Scissors beat Paper';
}
}
} */
function playRound(playerSelection, computerSelection) {
let playerSelect = playerSelection.toLowerCase();
if (playerSelect !== 'rock' && playerSelect !== 'paper' && playerSelect !== 'scissors') {
return 'You must enter a valid option (rock, paper or scissors)';
}
let computerSelect = computerSelection.toLowerCase();
if (playerSelect === computerSelect) {
return 'T';
} else if (playerSelect === 'rock') {
if (computerSelect === 'paper') {
return 'L';
} else {
return 'W';
}
} else if (playerSelect === 'paper') {
if (computerSelect === 'rock') {
return 'W';
} else {
return 'L';
}
} else {
if (computerSelect === 'rock') {
return 'L';
} else {
return 'W';
}
}
}
function game() {
let playerCount = 0;
let computerCount = 0;
for (let i = 1; i < 6; i++) {
let player = prompt('Please, enter your choice (Rock, Paper or Scissors): ');
let computer = computerPlay();
let result = playRound(player, computer);
if (result === 'W') {
console.log('You win round number ' + i);
playerCount++;
} else if (result === 'T') {
console.log("Round number " + i + " is a tie.");
} else if (result === 'L') {
console.log('You loose round number ' + i);
computerCount++;
}
}
console.log('Final result is Computer ' + computerCount + ' points and You ' + playerCount + ' points.');
}
</script>
</body>
</html>