Reputation: 5
i have this code from josex2r Jquery Slot Machine
this code shows whats currently active by showing what number of that active slot is (the js code)
<div id="machine1" class="slotMachine">
<div class="slot slot1"></div>
<div class="slot slot2"></div>
<div class="slot slot3"></div>
<div class="slot slot4"></div>
<div class="slot slot5"></div>
<div class="slot slot6"></div>
</div>
<div style="clear:both;">
<div id="machine1Result" class="slotMachine noBorder" style="text-align:left">Index: 0</div>
<div id="machine2Result" class="slotMachine noBorder" style="text-align:left">Index: 1</div>
<div id="machine3Result" class="slotMachine noBorder" style="text-align:left">Index: 2</div>
<div class="slotMachine noBorder"></div>
</div>
function onComplete($el, active){
switch($el[0].id){
case 'machine1':
$("#machine1Result").text("Index: "+active.index);
break;
case 'machine2':
$("#machine2Result").text("Index: "+active.index);
break;
case 'machine3':
$("#machine3Result").text("Index: "+active.index);
break;
}
}
The goal is ... once the user got the same result say "777" then change the background of some div. achieving same goal from here: Link
Upvotes: 0
Views: 884
Reputation: 9356
String together the 3 results and if == 777
use css()
to change background
function onComplete($el, active){
var m1Index;
var m2Index;
var m3Index;
switch($el[0].id) {
case 'machine1':
m1Index = active.index;
$("#machine1Result").text("Index: "+ m1Index );
break;
case 'machine2':
m2Index = active.index;
$("#machine2Result").text("Index: " + m2Index );
break;
case 'machine3':
m3Index = active.index;
$("#machine3Result").text("Index: "+ m3Index );
break;
}
if (m1Index & m2Index & m3Index) {
if ("" + m1Index + m2Index + m3Index == "777") {
$('.someDiv').css({"backgroundColor": "green"});
}
}
}
First check that all three index exist and then check if combination of strings equal 777
Adding ""
to if ("" +
forces the three numbers to a string
Upvotes: 1