在下面的代碼中,我想function 2
更改text
中的文本以完成循環。不幸的是,var rand
不會將text
更改爲另一個詞。相反,它會一直保持一直。使用Math.random獲取相同的值
var x = 0;
function function1() {
document.getElementById("text").textContent = rand;
}
function function2() {
if (document.getElementById("text").innerHTML === "Red") {
x += 1;
document.getElementById("text2").textContent = x;
function1();
}
}
//I have got the equivalent functions for blue, green and gold as well
var randomarray = ['Red', 'Blue', 'Green', 'Gold', ];
var rand = randomarray[Math.floor(Math.random() * randomarray.length)];
有人可以告訴我如何解決這個問題。
我不清楚你在問什麼:句子在語法上沒有多大意義。請重新表達你的問題。 –
那麼,你永遠不會改變'rand'。你設置一次就是這樣。如果你想'rand'改變你必須改變它。 –
如何?菲利克斯國王 – ZAZLEO