html - Simple vanilla javascript game -
i trying make simple slot machine game first 1 here.
the 1 in example above bit complex, need mine add few classes here , there @ simple click events.
long story short, have play button initiates slot machine (shows - done), , when slot machine shown, spin button appears, , when click button, can make add 1 class first combination (e.g. "bonus") adds css class , respective transitions desired effect.
and comes tricky part me, need click same spin button again, add different class time. has work 3 times, while when pressing 4-th time, need add class id='ad-cont'
div.
how can achieve vanilla js? know there must sort of loop here, can't figure out.
<div id="ad-cont"> <div id="slot-frame"><img class="frame" src="../frame.png"> <div class="frame-item"></div> <div class="frame-item"></div> <div class="frame-item"></div> <div class="frame-item"></div> <div class="frame-item"></div> </div><a id="play" href="#">play</a><a id="spin" href="#">spin</a> </div>
and here i've got far:
var adcontainer = document.getelementbyid('ad-cont'); var playbtn = document.getelementbyid('play'); var spinbtn = document.getelementbyid('spin'); var slotmachine = document.getelementbyid('slot-frame'); playbtn.addeventlistener('click', function(){ adcontainer.classlist.add('playing'); }); spinbtn.addeventlistener('click', function(){ slotmachine.classlist.add('bonus'); });
thank all!
have tried using switch , count resets itself?
var count = 0; spinbtn.addeventlistener('click', function(){ count++; switch(count) { case 1: slotmachine.classlist.add('bonus'); break; case 2: slotmachine.classlist.add('bonus2'); break; case 3: slotmachine.classlist.add('bonus3'); break; case 4: otheridelement.classlist.add('finished!'); count = 0; break; default: alert("error!"); } });
Comments
Post a Comment