javascript
1コード 2(function(){ 3 var pingoNumber = $('#pingo-number'); 4 var startButton = $('#start-button'); 5 var resetButton = $('#reset-button'); 6 var historiesDiv = $('#histories'); 7 8 // init histories 9 var toBingoString = function(n){ 10 if(n > 9) { 11 return n.toString(10); 12 } else if (n < 0) { 13 return '00'; 14 } else { 15 return '0' + n.toString(10); 16 } 17 }; 18 var addHistory = function(n) { 19 historiesDiv.append('<div class="col-md-1"><p class="history-number">' + toBingoString(n) + '</p></div>'); 20 }; 21 22 // init number list and storage 23 var numberListAll = []; 24 var maxNumber = 75; 25 for(var num = 1; num <= maxNumber; num++) { 26 numberListAll.push(num); 27 } 28 29 var storage = localStorage; 30 var listKey = 'partybingo.numberlist'; 31 var removedKey = 'partybingo.removedlist'; 32 var setNumberList = function(a) { 33 storage.setItem(listKey, JSON.stringify(a)); 34 }; 35 var getNumberList = function() { 36 return JSON.parse(storage.getItem(listKey)); 37 }; 38 var setRemovedList = function(a) { 39 storage.setItem(removedKey, JSON.stringify(a)); 40 }; 41 var getRemovedList = function() { 42 return JSON.parse(storage.getItem(removedKey)); 43 }; 44 var resetLists = function() { 45 setNumberList(numberListAll.concat()); 46 setRemovedList([]); 47 }; 48 49 // create initial list or loadHistory 50 var loadedNumberList = getNumberList(); 51 var loadedRemovedList = getRemovedList(); 52 if(loadedNumberList && loadedRemovedList) { 53 for (var i = 0; i < loadedRemovedList.length; i++) { 54 addHistory(loadedRemovedList[i]); 55 } 56 } else { 57 resetLists(); 58 } 59 60 // create util method 61 var getNumberRamdom = function(){ 62 var numberList = getNumberList(); 63 var i = Math.floor(Math.random() * numberList.length); 64 return numberList[i]; 65 }; 66 var removeNumberRamdom = function(){ 67 var numberList = getNumberList(); 68 if(numberList.length === 0) { 69 return -1; 70 } 71 var i = Math.floor(Math.random() * numberList.length); 72 var removed = numberList[i]; 73 numberList.splice(i, 1); 74 setNumberList(numberList); 75 var removedList = getRemovedList(); 76 removedList.push(removed); 77 setRemovedList(removedList); 78 return removed; 79 }; 80 81 // init start button 82 var isStarted = false; 83 function rourletto() { 84 if(isStarted) { 85 pingoNumber.text(toBingoString(getNumberRamdom())); 86 setTimeout(rourletto, 60); 87 } 88 } 89 var stop = function(time) { 90 isStarted = false; 91 startButton.text('Start'); 92 var n = removeNumberRamdom(); 93 pingoNumber.text(toBingoString(n)); 94 addHistory(n); 95 96 }; 97 var start = function(){ 98 isStarted = true; 99 startButton.text('Stop'); 100 101 rourletto(); 102 }; 103 var startClicked = function(e){ 104 if(isStarted) { 105 stop(null); 106 } else { 107 start(); 108 } 109 }; 110 startButton.click(startClicked); // button 111 startButton.focus(); 112 113 // init reset button 114 var resetClicked = function() { 115 if (confirm('リセットしてもよろしいですか?')) { 116 resetLists(); 117 pingoNumber.text('00'); 118 historiesDiv.empty(); 119 startButton.focus(); 120 } 121 }; 122 resetButton.click(resetClicked); 123 124if (loadedNumberList.length=0) { 125alert("") 126} 127})(); 128 129```HTML 130コード 131```ここに言語を入力 132<!DOCTYPE html> 133<html lang="ja"> 134 135<head> 136 <meta charset="utf-8"> 137 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 138 <meta name="viewport" content="width=device-width, initial-scale=1"> 139 <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> 140 <title>Party Bingo!</title> 141 142 <!-- Bootstrap --> 143 <link href="asset/bootstrap-3.3.5-dist/css/bootstrap.min.css" rel="stylesheet"> 144 <link rel="stylesheet" href="asset/partybingo.css"> 145 146 <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> 147 <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> 148 <!--[if lt IE 9]> 149 <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> 150 <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> 151 <![endif]--> 152</head> 153 154<body> 155 <p> 156 <span id="pingo-number">00</span></p> 157 <div id="buttons"> 158 <button id="start-button" class="btn btn-lg btn-default">Start</button> 159 <button id="reset-button" class="btn btn-lg btn-default">Reset</button> 160 </div> 161 <h3>Histories</h3> 162 <div id="histories" class="row histories"></div> 163 164 165 166 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 167 <script src="asset/jquery-1.11.3.min.js "></script> 168 <!-- Include all compiled plugins (below), or include individual files as needed --> 169 <script src="asset/bootstrap-3.3.5-dist/js/bootstrap.min.js "></script> 170 <script src="asset/partybingo.js "></script> 171 </body> 172</html>
githubで取得したビンゴマシンのコードを改良して数字をすべて引ききったらalertを行うコードを作成しています。現在ビンゴの結果として排出されていない数がなくなった場合にalertさせようと考えているのですが全ての数字を引ききってもalertされません。条件をどのようにしたらalertされるようになりますか。
1
回答1件
あなたの回答
tips
プレビュー