Javascript &引用;“未定义文档”;
我是JavaScript新手,我很难解决这个问题。多谢各位Javascript &引用;“未定义文档”;,javascript,loops,document,Javascript,Loops,Document,我是JavaScript新手,我很难解决这个问题。多谢各位 var attempts = 0; var randomNumber; while (randomNumber === 10) { randomNumber = (Math.random(10 - 1) + 1); attempts = attempts + 1; } document.write("It took " + attempts + " attempts"); 由于您正在调用document对象,因此代
var attempts = 0;
var randomNumber;
while (randomNumber === 10) {
randomNumber = (Math.random(10 - 1) + 1);
attempts = attempts + 1;
}
document.write("It took " + attempts + " attempts");
由于您正在调用
document
对象,因此代码应该包含在HTML代码段中。文档对象表示您的网页。如果要访问HTML页面中的任何元素,请始终从访问文档对象开始
例如:
<!DOCTYPE html>
<html>
<body>
<script>
var attempts = 0;
var randomNumber;
while (randomNumber === 10) {
randomNumber = (Math.random(10 - 1) + 1);
attempts = attempts + 1;
}
document.write("It took " + attempts + " attempts");
</script>
</body>
</html>
var=0;
var随机数;
而(随机数===10){
随机数=(数学随机数(10-1)+1);
尝试次数=尝试次数+1;
}
文件。写入(“需要”+尝试+”尝试);
其工作原理为何未定义?你想做什么?非常感谢!作为一个新手,这给了我很多非常有用的信息,我可以应用到其他事情上。谢谢