Skip to content

Commit 711fd28

Browse files
committed
finished stats logic
1 parent 37de13b commit 711fd28

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
SAMPLE PROJECT: Slot Machine
55
Completed as part of The JavaScript Full-Stack Bootcamp.
66
Instructor: Flavio Copes
7-
Last Edit: 8/4/20 by E.Cope Revised: 3/26/21
7+
Last Edit: 8/4/20 by E.Cope Revised: 3/27/21
88
-->
99
<head>
1010
<meta http-equiv="X-UA-Compatible" content="IE=edge">
@@ -113,7 +113,7 @@ <h2 class="stat ul" id="stats-title"><a onclick="resetLocalStorage()" href="java
113113
</p>
114114
</div>
115115

116-
<p id="author-date">Last editted: 3/26/21 by E.Cope --- Version 1.1.1 🎰</p>
116+
<p id="author-date">Last editted: 3/27/21 by E.Cope --- Version 1.1.1 🎰</p>
117117
</footer>
118118
</body>
119119

script.js

+27-21
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/**
1+
/*****************************************************************************
22
* script.js
33
* ---------
44
* Where all the fun happens :)
55
*
6-
* Created by: E.Cope Last edit: 3/27/21
7-
*/
6+
* Created by: E.Cope Last edit: 3/27/21
7+
*****************************************************************************/
88

99
//store the classes and ids we'll be manipulating
1010
const iconIdsArr = ["#icon-1", "#icon-2", "#icon-3", "#icon-4", "#icon-5"];
@@ -54,7 +54,7 @@ function magicAct(num1, num2, num3) {
5454
}
5555

5656
//checks to see if the player has won
57-
function winCondition(num1, num2, num3) {
57+
function winCondition(num1, num2, num3, spinCount) {
5858
if (num1 == num2 && num2 == num3) {
5959
//change sign to say WINNER!
6060
$("#try-your-luck").text("WINNER!");
@@ -64,9 +64,23 @@ function winCondition(num1, num2, num3) {
6464
$("#reset-btn").css("visibility", "visible");
6565

6666
//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+
}
7084
//refresh stats data
7185
refreshStats();
7286
}
@@ -112,14 +126,7 @@ function resetLocalStorage() {
112126
}
113127
}
114128

115-
//TODO
116-
function handleLeastMost() {
117-
let le = DataStore.least;
118-
let mo = DataStore.most;
119-
//...
120-
}
121-
122-
///////////////////////////////////////////////////////////////////////////////////
129+
///////////////////////////////////////////////////////////////////////////////
123130

124131
$(document).ready(function(){
125132
//clear slots
@@ -136,14 +143,16 @@ $(document).ready(function(){
136143
refreshStats();
137144

138145
} else {
139-
console.warn("Web Storage not supported!");
146+
console.warn("Web Storage not supported! \
147+
Features for this site will be missing.");
140148
}
141149

142150
//spin-btn event listener:
143151
$("#spin-btn").click(function(){
144152

145153
//CASE -- We Won:
146154
if ($("#try-your-luck").text() === "WINNER!") {
155+
147156
return;
148157
}
149158
//CASE -- We Lost:
@@ -168,12 +177,9 @@ $(document).ready(function(){
168177
//display the appropriate icons based on the random indices
169178
magicAct(dice[0], dice[1], dice[2]);
170179
//check if we've won
171-
winCondition(dice[0], dice[1], dice[2]);
180+
winCondition(dice[0], dice[1], dice[2], spinCount);
172181
}
173-
174-
//TOSO: update most and least spins stats
175-
handleLeastMost();
176-
182+
177183
//refresh stats
178184
refreshStats();
179185
});

0 commit comments

Comments
 (0)