javascriptでスロットマシンを作ろうとしたのですが、コンソール画面で
Uncaught ReferenceError: testTimer is not defined
at slotFunction (main.js:42)
at HTMLDocument.<anonymous> (main.js:37)
at mightThrow (jquery-3.4.1.js:3557)
at process (jquery-3.4.1.js:3625)
のエラーが出ます。
試したこと: testTimerに var testTimer の変数宣言をする
html
1**略** 2 <span id="aSlot"></span> 3 <span id="bSlot"></span> 4 <span id="cSlot"></span>
js
1$(function() { 2 3 var slotno = "a"; 4 // 初期値設定 5 6 slotFunction(slotno); 7 8 function slotFunction(slotno) { 9 let count = 0; 10 11 testTimer = setInterval(function(){ 12 13 if(count !==10) { 14 $('#'+slotno+'Slot').html(count++); 15 } 16 else { 17 count = 0; 18 $('#'+slotno+'Slot').html(count++); 19 } 20 },100); 21 }; 22 23 $(window).keydown(function(e) { 24 25 if(e.keyCode == 32) { 26 27 clearInterval(testTimer); 28 29 if(slotno == "a") { 30 31 slotno = "b"; 32 slotFunction(slotno); 33 } 34 else if(slotno == "b") { 35 slotno = "c"; 36 slotFunction(slotno); 37 } 38 else { 39 var slotnumA = $('#aSlot').text(); 40 var slotnumB = $('#bSlot').text(); 41 var slotnumC = $('#cSlot').text(); 42 43 allClearfunction(slotnumA, slotnumB, slotnumC); 44 }; 45 }; 46 return false; 47 48 }); 49 50 function allClearfunction(slotnumA, slotnumB, slotnumC) { 51 52 if(slotnumA == slotnumB && slotnumB == slotnumC) { 53 if(slotnumC == 7) { 54 alert("超当たり") 55 } 56 else { 57 alert("当たり") 58 } 59 }else { 60 alert("はずれ"); 61 62 slotno = "a"; 63 64 $("span").empty(); 65 66 slotFunction(slotono); 67 }; 68 }; 69});
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/10 14:07
2019/06/10 14:14