我试图让这个 for 循环正确运行,但事实并非如此。循环内的对象不运行,我不明白为什么。
for (i = 0; i < 26; i++) {
wordFound = Math.floor(Math.Random());
document.write(wordFound);
wordData = [wordFound];
if (wordFound != wordFound.indexOf(wordData)) {
document.write('Words being generated...');
} else {
document.write('Words being generated...');
}
}
最佳答案
Math.Random()
不是一个函数,应该是 Math.random() 。
此外,wordFound
不是字符串或数组,因此您不能使用 indexOf()
。
注意: Math.floor(Math.random())
将始终返回 O
。
希望这有帮助。
关于javascript - 为什么当我运行 For 循环时它不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34387393/