1+ function game ( ) {
2+ randNum = Math . floor ( Math . random ( ) * 3 )
3+ console . log ( randNum )
4+ if ( hand . RPS [ 0 ] . checked == true ) {
5+ you = "rock"
6+ }
7+ else if ( hand . RPS [ 1 ] . checked == true ) {
8+ you = "paper"
9+ }
10+ else if ( hand . RPS [ 2 ] . checked == true ) {
11+ you = "scissors"
12+ }
13+ console . log ( you )
14+ if ( randNum == 0 ) {
15+ randValue = "rock"
16+ }
17+ else if ( randNum == 1 ) {
18+ randValue = "paper"
19+ }
20+ else if ( randNum == 2 ) {
21+ randValue = "scissors"
22+ }
23+ console . log ( randValue )
24+ if ( you == randValue ) {
25+ returnResult = "You and the computer both chose " + you + ", therefore it is a tie" ;
26+ document . getElementById ( "result" ) . innerHTML = returnResult
27+ }
28+ else if ( you == "rock" && randValue == "paper" ) {
29+ returnResult = "You chose " + you + ", the computer chose " + randValue + ", so you lose" ;
30+ document . getElementById ( "result" ) . innerHTML = returnResult
31+ }
32+ else if ( you == "rock" && randValue == "scissors" ) {
33+ returnResult = "You chose " + you + ", the computer chose " + randValue + ", so you win" ;
34+ document . getElementById ( "result" ) . innerHTML = returnResult
35+ }
36+ else if ( you == "scissors" && randValue == "rock" ) {
37+ returnResult = "You chose " + you + ", the computer chose " + randValue + ", so you lose" ;
38+ document . getElementById ( "result" ) . innerHTML = returnResult
39+ }
40+ else if ( you == "scissors" && randValue == "paper" ) {
41+ returnResult = "You chose " + you + ", the computer chose " + randValue + ", so you win" ;
42+ document . getElementById ( "result" ) . innerHTML = returnResult
43+ }
44+ else if ( you == "paper" && randValue == "rock" ) {
45+ returnResult = "You chose " + you + ", the computer chose " + randValue + ", so you win" ;
46+ document . getElementById ( "result" ) . innerHTML = returnResult
47+ }
48+ else if ( you == "paper" && randValue == "scissors" ) {
49+ returnResult = "You chose " + you + ", the computer chose " + randValue + ", so you lose" ;
50+ document . getElementById ( "result" ) . innerHTML = returnResult
51+ }
52+ }
0 commit comments