-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
172 lines (130 loc) · 4.49 KB
/
main.js
File metadata and controls
172 lines (130 loc) · 4.49 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// const letter = ["R", "P", "S"]
// const randomIndex = letter[Math.floor(Math.random() * letter.length)];
// console.log(randomIndex);
// const letterTwo = ["R", "P", "S"]
// const randomIndexTwo = letterTwo[Math.floor(Math.random() * letterTwo.length)];
// console.log(randomIndexTwo);
// // the function that will be called by the unit test below
// const answer = ""
document.getElementById("rpc").onclick, document.getElementById("rpcTwo").onclick = rockPaperScissors (hand1, hand2) => {
if (hand1 === hand2) {
// answer = 'Its a tie'
return 'Its a tie'
document.getElementById("final").innerHTML = 'Its a tie!'
}
else if (hand1 === "S" && hand2 === "P") {
// answer = 'Its a tie'
return 'Player 1 wins!'
}
else if (hand1 === "S" && hand2 === "R") {
// answer = 'Its a tie'
return 'Player 2 wins!'
}
else if (hand1 === "P" && hand2 === "R") {
// answer = 'Its a tie'
return 'Player 1 wins!'
}
else if (hand1 === "P" && hand2 === "S") {
// answer = 'Its a tie'
return 'Player 2 wins!'
}
else if (hand1 === "R" && hand2 === "P") {
// answer = 'Its a tie'
return 'Player 2 wins!'
}
else if (hand1 === "R" && hand2 === "S") {
// answer = 'Its a tie'
return 'Player 1 wins!'
}
else {
return 'Something went wrong!'
}
}
const answer = ""
const rockPaperScissors = (hand1, hand2) => {
if (hand1 === hand2) {
answer = 'Its a tie'
return answer
}
else if (hand1 === "S" && hand2 === "P") {
answer = 'Its a tie'
return answer
}
else if (hand1 === "S" && hand2 === "R") {
answer = 'Its a tie'
return answer
}
else if (hand1 === "P" && hand2 === "R") {
answer = 'Its a tie'
return answer
}
else if (hand1 === "P" && hand2 === "S") {
answer = 'Its a tie'
return answer
}
else if (hand1 === "R" && hand2 === "P") {
answer = 'Its a tie'
return answer
}
else if (hand1 === "R" && hand2 === "S") {
answer = 'Its a tie'
return answer
}
else {
return 'Something went wrong!'
}
}
rockPaperScissors(randomIndex, randomIndexTwo)
// // uses strict mode so strings are not coerced, variables are not hoisted, etc...
// 'use strict';
// // brings in the assert module for unit testing
// const assert = require('assert');
// // brings in the readline module to access the command line
// const readline = require('readline');
// // use the readline module to print out to the command line
// const rl = readline.createInterface({
// input: process.stdin,
// output: process.stdout
// });
// // the function that will be called by the unit test below
// const rockPaperScissors = (hand1, hand2) => {
// // Write code here
// // Use the unit test to see what is expected
// }
// // the first function called in the program to get an input from the user
// // to run the function use the command: node main.js
// // to close it ctrl + C
// function getPrompt() {
// rl.question('hand1: ', (answer1) => {
// rl.question('hand2: ', (answer2) => {
// console.log( rockPaperScissors(answer1, answer2) );
// getPrompt();
// });
// });
// }
// // Unit Tests
// // You use them run the command: npm test main.js
// // to close them ctrl + C
// if (typeof describe === 'function') {
// // most are notes for human eyes to read, but essentially passes in inputs then compares if the function you built return the expected output.
// describe('#rockPaperScissors()', () => {
// it('should detect a tie', () => {
// assert.equal(rockPaperScissors('rock', 'rock'), "It's a tie!");
// assert.equal(rockPaperScissors('paper', 'paper'), "It's a tie!");
// assert.equal(rockPaperScissors('scissors', 'scissors'), "It's a tie!");
// });
// it('should detect which hand won', () => {
// assert.equal(rockPaperScissors('rock', 'paper'), "Hand two wins!");
// assert.equal(rockPaperScissors('paper', 'scissors'), "Hand two wins!");
// assert.equal(rockPaperScissors('rock', 'scissors'), "Hand one wins!");
// });
// it('should scrub input to ensure lowercase with "trim"ed whitepace', () => {
// assert.equal(rockPaperScissors('rOcK', ' paper '), "Hand two wins!");
// assert.equal(rockPaperScissors('Paper', 'SCISSORS'), "Hand two wins!");
// assert.equal(rockPaperScissors('rock ', 'sCiSsOrs'), "Hand one wins!");
// });
// });
// } else {
// // always returns ask the user for another input
// getPrompt();
// }