尋找來自那些比我更有見識的人的一些指導。隨機數字生成器Javascript - 範圍
我正在寫一個程序,提示用戶點擊一個按鈕,然後將生成到100
1的隨機整數我可以管理這部分罰款。我正在努力的是讓程序打印這個隨機整數的範圍,即我< = 33。
例如,當我點擊按鈕我想見:
「10比33更小的號碼」
或
「55是33和66之間的數字」
這是我的代碼到目前爲止,我已經把代碼,我在評論中有問題。
<!DOCTYPE HTML5>
<html>
<head>
<meta charset="UTF-8">
<title>question2</title>
</head>
<body>
<p>Click the button to display a random number from 1 to 100.</p>
<button onclick="myFunction()">Click here</button>
<p id="demo"></p>
<script>
function myFunction() {
var text = "";
var i = Math.floor((Math.random() * 100) + 1);
document.getElementById("demo").innerHTML = i;
}
// if (myFunction <= 33) {
// text += ("<br>" + i + " is a number less than or equal to 33");
// }
// if (myFunction > 34 and i < 65) {
// text += ("<br>" + i + " is a number between 33 and 66 (exclusive)");
// }
// if (my Function >= 66) {
// text += ("<br>" + i + " is a number greater than or equal to 66");
// }
</script>
</body>
</html>
謝謝你們。
其實,你與函數的概念掙扎。我可以建議退後一步,用普通的JavaScript播放一下沒有混淆瀏覽器/ DOM的考慮?您的shell中的nodejs將會是一個不錯的遊樂場。 –
@justsomebody NodeJS聽起來不像「普通JavaScript」。 [瀏覽器控制檯](http://webmasters.stackexchange.com/q/8525)已經足夠了。 – Xufox
@justsomebody對此我完全陌生,感謝您的建議,我想我一次試圖做得太多。需要更多的研究工作! – Keeron