<h1>Crystal Collector</h1>
<div id="crystal1" class="crystals"><img src="assets/images/purplecrystal.jpg"></div>
<div id="crystal2" class="crystals"><img src="assets/images/bluecrystal.jpg"></div>
<div id="crystal3" class="crystals"><img src="assets/images/greencrystal.jpg"></div>
<div id="crystal4" class="crystals"><img id="crystal4" src="assets/images/yellowcrystal.jpg"></div>
<div id="targetNumber" class="data">Number to Guess:<span id="targetNum"></span> </div>
<div id="results" class="data">Wins: <span id="wins"></span> Losses: <span id="losses"></span></div>
<div id="userTotal" class="data">Your Total: <span id="total"></span></div>
<script type="text/javascript">
$(document).ready(function() {
var targetNumber = Math.floor((Math.random()*138)+19);
var crystal1 = Math.floor((Math.random()*12)+1);
var crystal2 = Math.floor((Math.random()*12)+1);
var crystal3 = Math.floor((Math.random()*12)+1);
var crystal4 = Math.floor((Math.random()*12)+1);
var userNum = 0;
var wins = 0;
var losses = 0;
$("#wins").html(wins);
$("#losses").html(losses);
$("#total").html(userNum);
$("#targetNum").html(" " + targetNumber);
function reset() {
var targetNumber = Math.floor((Math.random()*138)+19);
var crystal1 = Math.floor((Math.random()*12)+1);
var crystal2 = Math.floor((Math.random()*12)+1);
var crystal3 = Math.floor((Math.random()*12)+1);
var crystal4 = Math.floor((Math.random()*12)+1);
var userNum = 0;
$("#total").html(userNum);
}
function victory() {
wins++;
reset();
$("#wins").html(wins);
}
function defeat() {
losses++;
reset();
$("#losses").html(losses);
}
$("#crystal1").click(function(){
userNum = userNum + crystal1;
alert("Total User: " + userNum + "\n Crystal1: " + crystal1);
$("#total").html(userNum);
if (userNum == targetNumber) {
userNum = 0;
victory();
}
else if (userNum > targetNumber) {
userNum = 0;
defeat();
}
});
$("#crystal2").click(function(){
userNum = userNum + crystal2;
alert("Total User: " + userNum + "\n Crystal2: " + crystal2);
$("#total").html(userNum);
if (userNum == targetNumber) {
userNum = 0;
victory();
}
else if (userNum > targetNumber) {
userNum = 0;
defeat();
}
});
$("#crystal3").click(function(){
userNum = userNum + crystal3;
alert("Total User: " + userNum + "\n Crystal3: " + crystal3);
$("#total").html(userNum);
if (userNum == targetNumber) {
userNum = 0;
victory();
}
else if (userNum > targetNumber) {
userNum = 0;
defeat();
}
});
$("#crystal4").click(function(){
userNum = userNum + crystal4;
alert("Total User: " + userNum + "\n Crystal4: " + crystal4);
$("#total").html(userNum);
if (userNum == targetNumber) {
victory();
userNum = 0;
}
else if (userNum > targetNumber) {
userNum = 0;
defeat();
}
});
});
</script>
</body>
//My reset function does not seem to working. Each crystal should have a new value once there is a win or loss. I even had to write "userNum = 0" for each click function, even though I wrote that out in my reset function.
I do not understand what is wrong with my reset function.