-
Notifications
You must be signed in to change notification settings - Fork 0
/
rps2.html
119 lines (94 loc) · 3.3 KB
/
rps2.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<script>
let winner;
let playerS;
let compS;
function computerPlay() {
let handChoice = ['Rock', 'Paper', 'Scissors'] // array of possible choices
let rando = handChoice[Math.floor(Math.random() * handChoice.length)];
let compS = rando.toString();
console.log(compS);
return compS;
}
function playerSelection() {
let playerChoice = prompt("What are you throwing down? Rock, Paper, or Scissors? Type your answer in.");
let playerToLower = playerChoice.toLowerCase();
let firstChar = playerToLower.charAt(0);
let firstCharCap = firstChar.toUpperCase();
let fPlayerChoice = firstCharCap + playerToLower.slice(1);
let playerS = fPlayerChoice.toString();
console.log(playerS);
return playerS;
}
function determineTie() {
if (computerPlay() === playerSelection()) {
// alert(`You both threw down the same thing. It's a Tie. Go again.`);
console.log("they tied")
} else {
// displayDecisions();
//alert("Not a tie, let's see who won!")
console.log("Not a tie. Let's see who won.")
determineWin();
}
return alert;
}
console.log(playerS);
console.log(compS);
function displayDecisions() {
alert(`You chose ${playerS}, and the computer chose ${compS}.`);
}
function determineWin() {
// rock
if (playerS === 'Rock') {
if (compS === 'Scissors') {
// alert("Rock Crushes Scissors, You Win!");
console.log("Player Wins");
} else {
alert("Paper Covers Rock, You Lose!");
console.log("Player Loses.");
}
// scissors
} else if (playerS=== 'Scissors') {
if (compS=== 'Paper') {
alert("Scissors Shreds Paper, You Win!");
console.log("Player Wins.");
} else {
alert("Rock Crushes Scissors, You Lose!");
console.log("Player Loses.");
}
// paper
} else if (playerS === 'Paper') {
if (compS === 'Rock') {
alert("Paper Covers Rock, You Win!");
console.log("Player Wins.");
} else {
alert("Scissors Shreds Paper, You Lose!");
console.log("Player Loses.");
}
// something else
} else {
//alert("Round Forfeit. Make sure you spell your word correctly next time.");
console.log("Player did not enter a valid word.");
}
}
// determineTie();
// The above works and now moving on for the game to have 5 rounds and score kept, and winner declared...
//// ****** things needed ******
// -function called game()
// -for loop to iterate 5 games
// -2 counters that increment based on outcome of each round in the game
//
// what functions currently are involved
// - determineTie()
// - computerPlay()
// - displayDecisions();
// - determineWin();
// - playerSelection();
function playRound(playerSelection, computerPlay) {
determineTie();
}
function game() {
playRound();
}
game();
</script>
reload page to try again.