-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (55 loc) · 3 KB
/
index.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
61
62
function computerPlay() {
const pick = ['rock', 'paper', 'scissors'];
return pick[Math.floor(Math.random() * pick.length)];
}
function playRound(playerSelection, computerSelection) {
if (computerSelection.toLowerCase() === playerSelection.toLowerCase()) {
console.log("It's a draw!");
return("Your Choice: " + playerSelection + ". " + "Computer: " + computerSelection);
} else if (computerSelection.toLowerCase() === "rock" && playerSelection.toLowerCase() === "scissors") {
console.log("Rock beats scissors! You lose :(");
return("Your Choice: " + playerSelection + ". " + "Computer: " + computerSelection);
} else if (computerSelection.toLowerCase() === "scissors" && playerSelection.toLowerCase() === "rock") {
console.log("Rock beats scissors! You win :D");
return("Your Choice: " + playerSelection + ". " + "Computer: " + computerSelection);
} else if (computerSelection.toLowerCase() === "scissors" && playerSelection.toLowerCase() === "paper") {
console.log("Scissors beats paper! You lose :(");
return("Your Choice: " + playerSelection + ". " + "Computer: " + computerSelection);
} else if (computerSelection.toLowerCase() === "paper" && playerSelection.toLowerCase() === "scissors") {
console.log("Scissors beats paper! You win :D");
return("Your Choice: " + playerSelection + ". " + "Computer: " + computerSelection);
} else if (computerSelection.toLowerCase() === "paper" && playerSelection.toLowerCase() === "rock") {
console.log("Paper beats rock! You lose :(");
return("Your Choice: " + playerSelection + ". " + "Computer: " + computerSelection);
} else if (computerSelection.toLowerCase() === "rock" && playerSelection.toLowerCase() === "paper") {
console.log("Paper beats rock! You win :D");
return("Your Choice: " + playerSelection + ". " + "Computer: " + computerSelection);
} else {
console.log("I'm not sure what, but something went worng :(");
}
}
const playerSelection = prompt("Start the game by picking among 'Rock, Paper, Scissors'").toLowerCase();
const computerSelection = computerPlay();
console.log(playRound(playerSelection, computerSelection))
function game() {
roundOne;
roundTwo;
roundThree;
roundFour;
roundFive;
}
const roundOne = playRound(playerSelection, computerSelection);
const roundTwo = playRound(playerSelection, computerSelection);
const roundThree = playRound(playerSelection, computerSelection);
const roundFour = playRound(playerSelection, computerSelection);
const roundFive = playRound(playerSelection, computerSelection);
// Print results of game round
console.log(game(playerSelection, computerSelection));
function game() {
for (let i = 0; i < 5; i++) {
const playerSelection = prompt();
const computerSelection = computerPlay();
const currentRound = playRound(playerSelection, computerSelection);
console.log(currentRound);
}
}