-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
92 lines (74 loc) · 3.22 KB
/
main.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
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
function game(getPlayerChoice, getComputerChoice) {
// this is the last part, not the first - but wrap the whole function in a loop
for (let i = 0; i < 5; i++) {
// define what 0, 1, and 2 are. 0 will equal rock, 1 will be paper, and 2 scissors
const items = ['Rock', 'Paper', 'Scissors'];
// ask the computer to choose one of these items
const getComputerChoice = Math.floor(Math.random() * items.length);
// test - console log
console.log(items[getComputerChoice]);
// we need to include a player selection too
let getPlayerChoice = prompt('Let\'s play rock, paper, scissors! Best out of 5 wins. Please type your selection below:');
// define 'out'
let out= ['rock', 'paper', 'scissors'];
// define 'player score'
let playerScore= 0;
// define 'computer score'
let computerScore= 0;
// define 'final'
let final= [playerScore, computerScore];
// now's the scary part. We're going to FIGHT!
function play() {
// if player chose rock
if (getPlayerChoice.toLowerCase() == 'rock') {
if (items[getComputerChoice] == 'Paper') {
out= ('You lose this round! Paper beats rock.');
computerScore = ++computerScore;
} else if (items[getComputerChoice] == 'Scissors') {
out= ('You win this round! Rock beats scissors.');
playerScore = ++playerScore;
} else if (items[getComputerChoice] == 'Rock') {
out= ('You tie this round!');
}
// if player chose paper
} else if (getPlayerChoice.toLowerCase() == 'paper') {
if (items[getComputerChoice] == 'Paper') {
out= ('You tie this round!');
} else if (items[getComputerChoice] == 'Scissors') {
out= ('You lose this round! Scissors beats paper.');
computerScore = ++computerScore;
} else if (items[getComputerChoice] == 'Rock') {
out= ('You win this round! Paper beats rock.');
playerScore = ++playerScore;
}
// if player chose scissors
} else if (getPlayerChoice.toLowerCase() == 'scissors') {
if (items[getComputerChoice] == 'Paper') {
out= ('You win this round! Scissors beats paper.');
playerScore = ++playerScore;
} else if (items[getComputerChoice] == 'Scissors') {
out= ('You tie this round!');
} else if (items[getComputerChoice] == 'Rock') {
out= ('You lose this round! Rock beats scissors.');
computerScore = ++computerScore;
}
// if player didn't choose RPS
} else {
console.log('Please choose only rock, paper, or scissors!');
}
}
// runs the function and gives us the result
play()
console.log(out)
}
// function for the end of the game
function end () {
console.log(final);
}
// define 'final'
let final= [playerScore, computerScore];
game();
console.log(out);
console.log(final);
}
// I'm done dealing with this script right now, it's irritating me, but it runs 5x then stops. I don't know how to make it declare a final winner yet.