我該如何在排序順序中做到這一點?如何將其變爲排序順序?
此位置分配:https://jsfiddle.net/debhxnqc/27/
的代碼是在這裏:
Guess:
<input type="textbox" id="index" value="12">
<br/> Get Number:
<button id="click" onclick="InsertGuess(1000,0,'',0)">Generate</button>
<div id="guess"></div>
<script>
var InsertGuess = function(max, min, finalStr, count) {
var str = 'Guessed :';
var guessnum = Math.floor(Math.random() * (max - min + 1) + min);
if (document.getElementById('index').value > guessnum) {
finalStr = finalStr.concat(guessnum, ' too low <br>');
count = count + 1;
return InsertGuess(max, guessnum, finalStr, count);
} else if (document.getElementById('index').value < guessnum) {
finalStr = finalStr.concat(guessnum, ' too high <br>');
count = count + 1;
return InsertGuess(guessnum, min, finalStr, count);
} else {
count = count + 1;
finalStr = finalStr.concat(guessnum, ' Got it !!!<br>');
finalStr = finalStr.concat('It took me ' + count + ' tries ');
document.getElementById('guess').innerHTML = finalStr;
return;
}
}
</script>
筆者獲悉,這需要在排序順序做按下「生成按鈕」時。
**Example**: When pressing generate the result would show:
532 too high
47 too high
14 too high
8 too low
10 too low
11 too low
12 Got it !!!
It took me 7 tries
相反,我被告知這需要顯示爲:
532 too high
147 too high
214 too high
98 too low
76 too low
45 too low
12 Got it !!!
It took me 7 tries
在排序順序。我會怎麼做?
使用數組(S),如果你要對它進行排序 – charlietfl