-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
60 lines (45 loc) · 1.66 KB
/
script.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
58
59
60
let gameOptions = ["rock", "paper", "scissors"];
function getComputerChoice() {
return gameOptions[Math.floor(Math.random()*gameOptions.length)];
}
function getPlayerSelection() {
return prompt("Enter your move: rock, paper, scissors");
}
let playerSelection;
let computerSelection;
function playRound(playerSelection, computerSelection) {
playerSelection = getPlayerSelection();
console.log("Player selected move :" + playerSelection);
computerSelection = getComputerChoice();
console.log(" Computer Selected move : " + computerSelection);
if (playerSelection == computerSelection) {
return "Tie";
} else if (playerSelection == "rock" && computerSelection == "scissors") {
return "You win! Rock beats Scissors";
} else if (playerSelection == "rock" && computerSelection == "paper") {
return "You Lose! Paper beats Rock";
} else if (playerSelection == "paper" && computerSelection == "rock") {
return "You win! Paper beats Rock";
} else if (playerSelection == "paper" && computerSelection == "scissors") {
return "You Lose! Scissors beats Paper";
} else if (playerSelection == "scissors" && computerSelection == "paper") {
return "You win! Scissors beats Paper";
} else if (playerSelection == "scissors" && computerSelection == "rock") {
return "You Lose! Rock beats Scissors";
} else {
return "1";
}
}
function game() {
for (i = 0; i < 5; i++) {
ans[i] = playRound(playerSelection, computerSelection);
}
}
let ans = new Array(5);
function result() {
for (i = 0; i < ans.length; i++) {
console.log(ans[i]);
}
}
game();
result();