1- function getComputerChoice ( ) {
1+ // eslint-disable-next-line import/no-unresolved
2+ import confetti from 'https://cdn.skypack.dev/canvas-confetti' ;
3+
4+ const party = ( ) => {
5+ confetti ( {
6+ particleCount : 100 ,
7+ spread : 90 ,
8+ origin : { y : 0.6 } ,
9+ } ) ;
10+ } ;
11+
12+ const getComputerChoice = ( ) => {
213 const rpsChoices = [ 'Rock' , 'Paper' , 'Scissors' ] ;
314 const computerChoice = rpsChoices [ Math . floor ( Math . random ( ) * 3 ) ] ;
415 return computerChoice ;
5- }
16+ } ;
617
7- function getResult ( playerChoice , computerChoice ) {
18+ const getResult = ( playerChoice , computerChoice ) => {
819 let score ;
920
1021 if ( playerChoice === computerChoice ) {
1122 score = 0 ;
12- } else if ( playerChoice === 'Rock' && computerChoice === 'Scissors' ) {
13- score = 1 ;
14- } else if ( playerChoice === 'Paper' && computerChoice === 'Rock' ) {
15- score = 1 ;
16- } else if ( playerChoice === 'Scissors' && computerChoice === 'Paper' ) {
23+ } else if (
24+ ( playerChoice === 'Rock' && computerChoice === 'Scissors' )
25+ || ( playerChoice === 'Paper' && computerChoice === 'Rock' )
26+ || ( playerChoice === 'Scissors' && computerChoice === 'Paper' )
27+ ) {
1728 score = 1 ;
1829 } else {
1930 score = - 1 ;
2031 }
2132
2233 return score ;
23- }
34+ } ;
2435
25- function showResult ( score , playerChoice , computerChoice ) {
36+ const showResult = ( score , playerChoice , computerChoice ) => {
2637 const result = document . getElementById ( 'result' ) ;
38+
2739 // eslint-disable-next-line default-case
2840 switch ( score ) {
2941 case - 1 :
@@ -34,38 +46,40 @@ function showResult(score, playerChoice, computerChoice) {
3446 break ;
3547 case 1 :
3648 result . innerText = 'You Win!' ;
49+ party ( ) ;
3750 break ;
3851 }
3952
4053 const playerScore = document . getElementById ( 'player-score' ) ;
4154 const hands = document . getElementById ( 'hands' ) ;
4255 playerScore . innerText = `${ Number ( playerScore . innerText ) + score } ` ;
4356 hands . innerText = `👱 ${ playerChoice } vs 🤖 ${ computerChoice } ` ;
44- }
57+ } ;
4558
46- function onClickRPS ( playerChoice ) {
59+ const onClickRPS = ( playerChoice ) => {
4760 const computerChoice = getComputerChoice ( ) ;
48- const score = getResult ( playerChoice . value , computerChoice ) ;
49- showResult ( score , playerChoice . value , computerChoice ) ;
50- }
61+ const score = getResult ( playerChoice , computerChoice ) ;
62+ showResult ( score , playerChoice , computerChoice ) ;
63+ } ;
5164
52- function endGame ( ) {
65+ const endGame = ( ) => {
5366 const playerScore = document . getElementById ( 'player-score' ) ;
5467 const hands = document . getElementById ( 'hands' ) ;
5568 const result = document . getElementById ( 'result' ) ;
5669 playerScore . innerText = '' ;
5770 hands . innerText = '' ;
5871 result . innerText = '' ;
59- }
72+ } ;
6073
61- function playGame ( ) {
74+ const playGame = ( ) => {
6275 const rpsButtons = document . querySelectorAll ( '.rpsButton' ) ;
6376
6477 rpsButtons . forEach ( ( rpsButton ) => {
65- rpsButton . onclick = ( ) => onClickRPS ( rpsButton ) ;
78+ rpsButton . onclick = ( ) => onClickRPS ( rpsButton . value ) ;
6679 } ) ;
6780
6881 const endGameButton = document . getElementById ( 'endGameButton' ) ;
6982 endGameButton . onclick = ( ) => endGame ( ) ;
70- }
83+ } ;
84+
7185playGame ( ) ;
0 commit comments