這段代碼不工作,因爲我會喜歡它,但我不知道這個問題。此JavaScript代碼無效。我的語法錯了還是其他的東西?
代碼:JavaScript中的經驗
<body>
var randNumForQuote = Math.floor((Math.random() * 11));
if (randNumForQuote == 0) {
document.getElementById("quoteDiv").innerHTML = "Hello";
} else if (randNumForQuote == 1) {
document.getElementById("quoteDiv").innerHTML = "Hello1";
} else if (randNumForQuote == 2) {
document.getElementById("quoteDiv").innerHTML = "Hello2";
} else if (randNumForQuote == 3) {
document.getElementById("quoteDiv").innerHTML = "Hello3";
} else if (randNumForQuote == 4) {
document.getElementById("quoteDiv").innerHTML = "Hello4";
} else if (randNumForQuote == 5) {
document.getElementById("quoteDiv").innerHTML = "Hello5";
} else if (randNumForQuote == 6) {
document.getElementById("quoteDiv").innerHTML = "Hello6";
} else if (randNumForQuote == 7) {
document.getElementById("quoteDiv").innerHTML = "Hello7";
} else if (randNumForQuote == 8) {
document.getElementById("quoteDiv").innerHTML = "Hello8";
} else if (randNumForQuote == 9) {
document.getElementById("quoteDiv").innerHTML = "Hello9";
} else if (randNumForQuote == 10) {
document.getElementById("quoteDiv").innerHTML = "Hello10";
}
<div id="quoteDiv"></div>
</body>
我有限的,所以不明白這個問題太清楚。
我期待股利說的輸出之一(例如Hello, Hello1, Hello2, etc.
)
你忘了告訴我們你的期待。這個代碼工作,因爲它是寫.. – Rayon
此代碼爲我工作的罰款。如果你有很多條件,最好使用'switch'語句。 – sabith
對不起,您會添加 –