1
- /**
1
+ /*****************************************************************************
2
2
* script.js
3
3
* ---------
4
4
* Where all the fun happens :)
5
5
*
6
- * Created by: E.Cope Last edit: 3/27/21
7
- */
6
+ * Created by: E.Cope Last edit: 3/27/21
7
+ ***************************************************************************** /
8
8
9
9
//store the classes and ids we'll be manipulating
10
10
const iconIdsArr = [ "#icon-1" , "#icon-2" , "#icon-3" , "#icon-4" , "#icon-5" ] ;
@@ -54,7 +54,7 @@ function magicAct(num1, num2, num3) {
54
54
}
55
55
56
56
//checks to see if the player has won
57
- function winCondition ( num1 , num2 , num3 ) {
57
+ function winCondition ( num1 , num2 , num3 , spinCount ) {
58
58
if ( num1 == num2 && num2 == num3 ) {
59
59
//change sign to say WINNER!
60
60
$ ( "#try-your-luck" ) . text ( "WINNER!" ) ;
@@ -64,9 +64,23 @@ function winCondition(num1, num2, num3) {
64
64
$ ( "#reset-btn" ) . css ( "visibility" , "visible" ) ;
65
65
66
66
//add 1 to wins stat
67
- DataStore . wins += 1 ;
68
- LocalStore . setItem ( "NUM_WINS" , DataStore . wins ) ;
69
-
67
+ let DS = DataStore ;
68
+ let LS = LocalStore ;
69
+ DS . wins += 1 ;
70
+ LS . setItem ( "NUM_WINS" , DataStore . wins ) ;
71
+
72
+ //update least and most spins stats
73
+ let least = DS . least ;
74
+ if ( least == 0 ) {
75
+ least = 9999 ;
76
+ }
77
+ let most = DS . most ;
78
+ if ( spinCount > most ) {
79
+ LS . setItem ( "MOST_SPINS" , spinCount ) ;
80
+ }
81
+ if ( spinCount < least ) {
82
+ LS . setItem ( "LEAST_SPINS" , spinCount ) ;
83
+ }
70
84
//refresh stats data
71
85
refreshStats ( ) ;
72
86
}
@@ -112,14 +126,7 @@ function resetLocalStorage() {
112
126
}
113
127
}
114
128
115
- //TODO
116
- function handleLeastMost ( ) {
117
- let le = DataStore . least ;
118
- let mo = DataStore . most ;
119
- //...
120
- }
121
-
122
- ///////////////////////////////////////////////////////////////////////////////////
129
+ ///////////////////////////////////////////////////////////////////////////////
123
130
124
131
$ ( document ) . ready ( function ( ) {
125
132
//clear slots
@@ -136,14 +143,16 @@ $(document).ready(function(){
136
143
refreshStats ( ) ;
137
144
138
145
} else {
139
- console . warn ( "Web Storage not supported!" ) ;
146
+ console . warn ( "Web Storage not supported! \
147
+ Features for this site will be missing." ) ;
140
148
}
141
149
142
150
//spin-btn event listener:
143
151
$ ( "#spin-btn" ) . click ( function ( ) {
144
152
145
153
//CASE -- We Won:
146
154
if ( $ ( "#try-your-luck" ) . text ( ) === "WINNER!" ) {
155
+
147
156
return ;
148
157
}
149
158
//CASE -- We Lost:
@@ -168,12 +177,9 @@ $(document).ready(function(){
168
177
//display the appropriate icons based on the random indices
169
178
magicAct ( dice [ 0 ] , dice [ 1 ] , dice [ 2 ] ) ;
170
179
//check if we've won
171
- winCondition ( dice [ 0 ] , dice [ 1 ] , dice [ 2 ] ) ;
180
+ winCondition ( dice [ 0 ] , dice [ 1 ] , dice [ 2 ] , spinCount ) ;
172
181
}
173
-
174
- //TOSO: update most and least spins stats
175
- handleLeastMost ( ) ;
176
-
182
+
177
183
//refresh stats
178
184
refreshStats ( ) ;
179
185
} ) ;
0 commit comments